summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-05-23 07:02:44 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-05-23 07:02:44 -0600
commit1b957501729f74c052a43b0cae64e19634adbec6 (patch)
tree008cd0dc0b6308a9d49667531d2e728c0a0eac94
parentbc6a12f6a5495486b65712fb075f4c3a6448ec78 (diff)
downloadnuttx-1b957501729f74c052a43b0cae64e19634adbec6.tar.gz
nuttx-1b957501729f74c052a43b0cae64e19634adbec6.tar.bz2
nuttx-1b957501729f74c052a43b0cae64e19634adbec6.zip
poll should ignore invalid file descriptors
-rw-r--r--nuttx/ChangeLog2
-rw-r--r--nuttx/fs/fs_poll.c56
2 files changed, 36 insertions, 22 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index c04f36995..f486c4cc2 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -4772,4 +4772,6 @@
correct usage of the socket API. Contributed by Max Holtzberg (2013-5-22).
* configs/stm32ldiscovery/src/stm32_lcd.c: Framework for support of the
STM32L-Discovery's segment LCD (2013-5-22).
+ * fs/fs_poll.c: Poll setup/teardown logic should ignore invalid (i.e.,
+ negative) file descriptors. Max Holtzberg (2013-5-23).
diff --git a/nuttx/fs/fs_poll.c b/nuttx/fs/fs_poll.c
index 2e3adeb5d..9c5ba39fe 100644
--- a/nuttx/fs/fs_poll.c
+++ b/nuttx/fs/fs_poll.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/fs_poll.c
*
- * Copyright (C) 2008-2009, 2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2008-2009, 2012-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -140,6 +140,7 @@ static int poll_fdsetup(int fd, FAR struct pollfd *fds, bool setup)
ret = (int)inode->u.i_ops->poll(this_file, fds, setup);
}
+
return ret;
}
#endif
@@ -162,20 +163,26 @@ static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds, sem_t *sem)
for (i = 0; i < nfds; i++)
{
- /* Setup the poll descriptor */
+ /* Ignore negative descriptors */
- fds[i].sem = sem;
- fds[i].revents = 0;
- fds[i].priv = NULL;
+ if (fds[i].fd >= 0)
+ {
+ /* Setup the poll descriptor */
- /* Set up the poll */
+ fds[i].sem = sem;
+ fds[i].revents = 0;
+ fds[i].priv = NULL;
- ret = poll_fdsetup(fds[i].fd, &fds[i], true);
- if (ret < 0)
- {
- return ret;
+ /* Set up the poll */
+
+ ret = poll_fdsetup(fds[i].fd, &fds[i], true);
+ if (ret < 0)
+ {
+ return ret;
+ }
}
}
+
return OK;
}
#endif
@@ -201,24 +208,29 @@ static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds, int *count)
*count = 0;
for (i = 0; i < nfds; i++)
{
- /* Teardown the poll */
+ /* Ignore negative descriptors */
- status = poll_fdsetup(fds[i].fd, &fds[i], false);
- if (status < 0)
+ if (fds[i].fd >= 0)
{
- ret = status;
- }
+ /* Teardown the poll */
- /* Check if any events were posted */
+ status = poll_fdsetup(fds[i].fd, &fds[i], false);
+ if (status < 0)
+ {
+ ret = status;
+ }
- if (fds[i].revents != 0)
- {
- (*count)++;
- }
+ /* Check if any events were posted */
- /* Un-initialize the poll structure */
+ if (fds[i].revents != 0)
+ {
+ (*count)++;
+ }
- fds[i].sem = NULL;
+ /* Un-initialize the poll structure */
+
+ fds[i].sem = NULL;
+ }
}
return ret;