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

   fs: Do not read past size in fs_heap_strndup.
   
   ## Summary
   
     * `fs_heap_strndup()` copied `strnlen(s, size) + 1` bytes from `s`. If `s` 
is not NUL-terminated within `size`, that reads `s[size]`.
     * Copy `strnlen(s, size)` bytes and write the NUL, matching `nx_strndup()` 
/ `strndup()` in `libs/libc/string/lib_strndup.c`.
     * Related issue: https://github.com/apache/nuttx/issues/22568
   
   ## Impact
   
     * Is new feature added? Is existing feature changed? NO. Bugfix of the 
unterminated-buffer path.
     * Impact on user? NO.
     * Impact on build? NO.
     * Impact on hardware? NO. Architecture-independent C.
     * Impact on documentation? NO.
     * Impact on security? YES. Avoids a 1-byte overread of the source buffer.
     * Impact on compatibility? NO. NUL-terminated inputs still produce the 
same string.
   
   ## Testing
   
     I confirm that changes are verified on local setup and works as intended:
     * Build Host(s): Ubuntu 24.04, x86_64, gcc 13.3.0
     * Target(s): host unit test of the copy length and payloads 
(arch-independent helper)
   
   ```
   $ ./tools/checkpatch.sh -f fs/fs_heap.c
   All checks pass.
   ```
   
   ```
   PASS old copy length: 5 (overread)
   PASS new copy length: 4
   PASS new_strndup unterminated: "abcd"
   PASS new_strndup truncate: "hel"
   PASS new_strndup short: "hi"
   PASS old_strndup short still works: "hi"
   ALL TESTS PASSED
   ```


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