nuttx/libs/libc
Xiang Xiao fa1bbce9c9 libc/stdio: allocate a buffer in getdelim() when *lineptr is NULL
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).

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2026-09-23 12:52:09 +08:00
..
aio
assert
audio
builtin
ctype
dirent
dlfcn
elf
errno
eventfd
fdt
fixedmath
gdbstub
gnssutils
grp
hex2bin
inttypes
libgen
locale
lzf
machine
misc
net
netdb
obstack
pthread
pwd
queue
regex
sched
search
semaphore
signal
spawn
stdio libc/stdio: allocate a buffer in getdelim() when *lineptr is NULL 2026-09-23 12:52:09 +08:00
stdlib
stream
string
symtab
syslog
termios
time
tls
uio
unistd
userfs
uuid
wchar
wctype
wqueue
zoneinfo
.gitignore
CMakeLists.txt
Kconfig
libc.csv
libc.h
limits_check.c
Makefile