mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 05:42:05 +08:00
poll: fix covertify issue about out-of-bound access fds
when i is zero and file_get is failed, num is -1, it's uint32_max for nfds. so remove num and simplify code logic. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
+6
-11
@@ -161,25 +161,20 @@ static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds,
|
||||
if (fds[i].fd >= 0)
|
||||
{
|
||||
FAR struct file *filep;
|
||||
int num = i;
|
||||
|
||||
ret = file_get(fds[i].fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
num -= 1;
|
||||
}
|
||||
else
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = file_poll(filep, &fds[i], true);
|
||||
if (ret < 0)
|
||||
{
|
||||
file_put(filep);
|
||||
}
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
if (num >= 0)
|
||||
{
|
||||
poll_teardown(fds, num, &count);
|
||||
}
|
||||
|
||||
poll_teardown(fds, i, &count);
|
||||
fds[i].revents |= POLLERR;
|
||||
fds[i].arg = NULL;
|
||||
fds[i].cb = NULL;
|
||||
|
||||
Reference in New Issue
Block a user