"if (dir)" converts the Fd to int, so a failed open (-1) is true and
fdopendir(dup(-1)) runs. Use "!!dir".
The test came in with commit
54d1cb5b63c7aad574a684a81440f0adccbc4fdf
("fd: add safer_path_walk for safer multi-component traversal").
Assisted-by: Claude-Code:claude-opus-5-5
if (S_ISDIR(st.st_mode)) {
// Walk children. Skip "." and ".." by using openat.
const Fd dir(open(path.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC));
- if (dir) {
+ if (!!dir) {
DIR *d = fdopendir(dup(dir));
if (d) {
while (auto *e = readdir(d)) {