zyfeier opened a new pull request, #22099:
URL: https://github.com/apache/nuttx/pull/22099

   ## Summary
   
   **Why.** `select()` / `pselect()` with no descriptor to watch (`nfds == 0`,
   used to wait for a signal or a timeout) has no poll set, so `pollset` stays
   NULL. Since a05b1f8cb88 ("vfs: change fs_heap to lib_tempbuffer"),
   `select()` still clears it with `memset(NULL, 0, 0)` and gives it back with
   `lib_put_tempbuffer(NULL)`. Passing NULL to `memset()` is undefined even
   with a zero length, and `lib_put_tempbuffer()` computes an index from the
   pointer. sim:ostest is built with UBSan and traps there (SIGILL) in the
   pselect() case of the new `pwait_test` (apache/nuttx-apps#4073).
   
   **What.** Clear and release the poll set only when it was allocated.
   
   ## Impact
   
   - Users / API: none.
   - Behavior: none for `nfds > 0`. `select()` with no descriptor no longer
     calls `memset()` and `lib_put_tempbuffer()` on NULL.
   - Build, hardware, documentation, security, compatibility: none.
   
   ## Testing
   
   sim:ostest (KASAN, UBSan with UBSAN_TRAP_ON_ERROR), apps 6dce52b7c36:
   
   | | result |
   |---|---|
   | master ff4d9b2ec67 | SIGILL at fs_select.c:182 (`ud2`), from pselect() in 
pwait_check() |
   | this PR | `pwait_test: PASS`, `ostest_main: Exiting with status 0` |
   
   tools/checkpatch.sh -c -u -m -g master..HEAD: All checks pass.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to