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

   ## Summary
   POSIX requires `getdelim()`/`getline()` to allocate a new buffer whenever 
`*lineptr` is NULL, regardless of the value of `*n`. The previous code read the 
buffer size from `*n` unconditionally and only fell back to the initial size 
when `*n` was zero, so a caller that passes `*lineptr == NULL` together with an 
uninitialized (non-zero) `*n` caused `lib_malloc()` to be invoked with that 
garbage size and typically fail with `ENOMEM`.
   
   Treat a NULL `*lineptr` the same as a zero `*n`: (re)allocate from the known 
`BUFSIZE_INIT` and ignore the untrusted `*n`. This matches the glibc behaviour 
that portable code relies on (for example toybox `grep`, which calls 
`getdelim()` with an uninitialized size variable).
   
   ## Impact
   - Only modifies `libs/libc/stdio/lib_getdelim.c`; `getline()` shares the 
same implementation and benefits from the same fix.
   
   ## Testing
   Built and booted `sim:nsh` on Linux; verified `getline()` with `*lineptr == 
NULL` and an uninitialized `*n` now succeeds instead of returning `ENOMEM`.


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