This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 5e4ecd1d603 fs/vfs: do not touch the poll set of select() without
descriptors
5e4ecd1d603 is described below
commit 5e4ecd1d6035e5f07feed972d31b7e14b69755ab
Author: zhangyuan29 <[email protected]>
AuthorDate: Fri Nov 20 13:08:08 2026 +0800
fs/vfs: do not touch the poll set of select() without descriptors
select() and pselect() with no descriptor to watch, used to wait for a
signal or a timeout, have no poll set: pollset stays NULL. Since
a05b1f8cb88 ("vfs: change fs_heap to lib_tempbuffer") select() still
cleared it with memset(NULL, 0, 0) and gave it back with
lib_put_tempbuffer(NULL). Passing NULL to memset() is undefined even
with a zero length, and sim:ostest, built with UBSan, traps there in
the new pselect() case of pwait_test.
Clear and release the poll set only when it was allocated.
Signed-off-by: zhangyuan29 <[email protected]>
---
fs/vfs/fs_select.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/vfs/fs_select.c b/fs/vfs/fs_select.c
index 077c5b0c620..b5ae12af85f 100644
--- a/fs/vfs/fs_select.c
+++ b/fs/vfs/fs_select.c
@@ -177,9 +177,9 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set
*writefds,
set_errno(ENOMEM);
return ERROR;
}
- }
- memset(pollset, 0, npfds * sizeof(struct pollfd));
+ memset(pollset, 0, npfds * sizeof(struct pollfd));
+ }
/* Initialize the descriptor list for poll() */
@@ -311,6 +311,10 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set
*writefds,
}
}
- lib_put_tempbuffer(pollset);
+ if (pollset != NULL)
+ {
+ lib_put_tempbuffer(pollset);
+ }
+
return ret;
}