]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
Fix getcwd(NULL, 0): allocate buffer when buf is NULL (glibc extension)
authorTulio A M Mendes <[email protected]>
Sun, 19 Apr 2026 17:55:59 +0000 (14:55 -0300)
committerTulio A M Mendes <[email protected]>
Sun, 19 Apr 2026 17:55:59 +0000 (14:55 -0300)
commit13b43e0ea66930cee10969fd9c70bdf0de500e30
tree8e7faac71f76327034767487845ef078e9486703
parentf4944a2d6d73af36ebacb0c057f2d842d66e8e8e
Fix getcwd(NULL, 0): allocate buffer when buf is NULL (glibc extension)

Bash calls getcwd(NULL, 0) — a glibc extension where NULL means
"allocate a buffer for me". Both ulibc and newlib wrappers passed
NULL straight to the kernel syscall, which returned -EFAULT because
the kernel rejects user_buf == NULL.

This caused:
  shell-init: error retrieving current directory: getcwd:
  cannot access parent directories: Bad address

Now both wrappers handle NULL buf by malloc'ing a buffer (4096 bytes
if size is 0), passing it to the kernel, and returning the allocated
pointer on success (or freeing it on error). This matches glibc
behavior and unblocks bash and other ported software.
newlib/libgloss/adros/posix_stubs.c
user/ulibc/src/unistd.c