nuttx/libs/libc/termios
Junbo Zheng 82b2f1993b libc/termios: Fix the ttyname_r buffer overflow with long tty paths.
ttyname_r() passed the caller buffer straight to fcntl(F_GETPATH)
whenever buflen >= TTY_NAME_MAX, but every FIOC_FILEPATH handler
writes the path bounded by PATH_MAX and ignores the caller buffer
size.  A tty registered under a nested /dev path, or reached through
rpmsgfs, has a path longer than TTY_NAME_MAX and overwrote the caller
buffer, silently corrupting memory behind a zero return code.  The
small-buffer branch had the same defect against its own stack local
char name[TTY_NAME_MAX].  Gate the direct write on PATH_MAX instead
and stage the path through a PATH_MAX path buffer obtained via
lib_get_tempbuffer(), returning ERANGE when it does not fit.

Verified on sim:nsh with a test driver registered at an 85-character
tty path: pre-fix, ttyname_r(buf, TTY_NAME_MAX) returned 0 and
smashed the canaries behind the buffer, and the small-buffer branch
panicked; post-fix both cases return ERANGE with the canaries intact.

Assisted-by: Claude Code (glm-5.3) <claude@anthropic.com>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2026-10-05 18:42:52 +08:00
..
CMakeLists.txt drivers/serial: add job-control TTY ioctls and libc wrappers 2026-06-23 16:26:53 -03:00
lib_cfmakeraw.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
lib_cfspeed.c libs: unify Private Types banners 2025-05-28 10:17:15 +08:00
lib_isatty.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
lib_tcdrain.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
lib_tcflow.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
lib_tcflush.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
lib_tcgetattr.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
lib_tcgetpgrp.c drivers/serial: add job-control TTY ioctls and libc wrappers 2026-06-23 16:26:53 -03:00
lib_tcgetsid.c drivers/serial: add job-control TTY ioctls and libc wrappers 2026-06-23 16:26:53 -03:00
lib_tcsendbreak.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
lib_tcsetattr.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
lib_tcsetpgrp.c drivers/serial: add job-control TTY ioctls and libc wrappers 2026-06-23 16:26:53 -03:00
lib_ttyname.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
lib_ttynamer.c libc/termios: Fix the ttyname_r buffer overflow with long tty paths. 2026-10-05 18:42:52 +08:00
Make.defs drivers/serial: add job-control TTY ioctls and libc wrappers 2026-06-23 16:26:53 -03:00