Skip to content

fix: empty stat-family paths - #882

Merged
alexcrichton merged 1 commit into
WebAssembly:mainfrom
eduardomourar:fix/empty-stat-paths
Oct 1, 2026
Merged

alexcrichton merged 1 commit into
WebAssembly:mainfrom
eduardomourar:fix/empty-stat-paths

Conversation

@eduardomourar

@eduardomourar eduardomourar commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Return ENOENT from stat, lstat, and fstatat for an empty pathname, instead of resolving to the preopened directory. Add AT_EMPTY_PATH support to fstatat, which operates on the descriptor itself when the path is empty.

Closes #881.

POSIX stat() requires ENOENT for an empty path.

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure why, but the tests on CI look like they're failing:

 87/219 Test #157: stat.wasm ...................................***Failed    0.05 sec
/home/runner/work/wasi-libc/wasi-libc/test/src/stat.c:32: stat("", &st) == -1 && errno == ENOENT failed: errno = Success
/home/runner/work/wasi-libc/wasi-libc/test/src/stat.c:34: lstat("", &st) == -1 && errno == ENOENT failed: errno = Success


int __wasilibc_nocwd_fstatat(int fd, const char *restrict path, struct stat *restrict buf,
int flag) {
if (path[0] == '\0') {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also check flag for AT_EMPTY_PATH and skip this check in that case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you it should be taken into account. I was looking into POSIX.1-2017 documentation, which does not reference the flag, so I will update the description pointing to POSIX.1-2024 docs.

@eduardomourar
eduardomourar force-pushed the fix/empty-stat-paths branch 3 times, most recently from 6c0e038 to 059da59 Compare September 30, 2026 22:24

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@alexcrichton
alexcrichton merged commit 165235b into WebAssembly:main Oct 1, 2026
36 checks passed
@eduardomourar
eduardomourar deleted the fix/empty-stat-paths branch October 1, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lstat("") resolves to the base directory instead of returning ENOENT

2 participants