Configuration Information [Automatically generated, do not change][RW: The configuration info generated by bashbug is useless, as it is a cross build]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -g -O2 uname output: Linux foxxylove 6.4.0-150600.23.47-default #1 SMP PREEMPT_DYNAMIC Thu Apr 3 03:44:04 UTC 2025 (2854fd7) x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.2 Patch Level: 37 Release Status: release Description: getcwd() as implemented in lib/sh/getcwd.c can return with NULL and a stale errno value if the algorithm fails. It aborts if readdir() returns NULL and no matching directory entry was found. But bash's getcwd() assumes that NULL from readdir() is always an error, which is not the case. This can happen on filesystems where d_ino != st_ino such as on Linux's OverlayFS. I have observed error messages like: shell-init: error retrieving current directory: getcwd: cannot access parent directories: Inappropriate ioctl for device Or: shell-init: error retrieving current directory: getcwd: cannot access parent directories: Success Repeat-By: The problem happens when the bash getcwd() implementation is used and the filesystem has odd semantics regarding inode numbers reported by readdir() and stat(). Such semantics can happen with OverayFS on Linux but also with many other network or userspace filesystems. Fix: I suggest as a fix setting errno to 0 before calling readdir() to distinguish between the error and end-of-directory case and setting errno to EINVAL or such if the algorithm is unable to determine the directory name.