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

   ## Summary
   
   `inotify_add_watch()` gets the absolute path from `lib_realpath()`
   with a NULL buffer, which allocates it with `lib_malloc()`, and then
   frees it with `fs_heap_free()`. With `CONFIG_FS_HEAPSIZE > 0` the fs
   heap is a separate heap, so the buffer is released into the wrong heap.
   
   Resolve the path into a buffer from `lib_get_tempbuffer()` and release
   it with `lib_put_tempbuffer()`. When `lib_realpath()` fails, return
   the errno it set.
   
   ## Impact
   
   Fixes an assertion (or heap corruption without assertions) on every
   `inotify_add_watch()` call when the fs heap is enabled. Builds without
   a separate fs heap behave as before.
   
   ## Testing
   
   Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master 
03aea78639, `sim:nsh` with
   `CONFIG_FS_NOTIFY=y`, `CONFIG_FS_SHMFS=y`, `CONFIG_FS_HEAPSIZE=65536`.
   A small test program calls `inotify_add_watch()` on `/tmp` ten times
   and once on a missing path:
   
   | case | master | this PR |
   |---|---|---|
   | `inotify_add_watch(fd, "/tmp", IN_CREATE)` | `Assertion failed 
mm_heapmember(heap, mem)` in `mm_free()` | returns a watch descriptor |
   | `inotify_add_watch(fd, "/no/such/dir", IN_CREATE)` | not reached | -1, 
ENOENT |
   
   - `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
   - Make and CMake builds pass; `ostest` exits with status 0.
   


-- 
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