Skip to content

Commit a829eba

Browse files
Dan Gohmanjohn-sharratt
authored andcommitted
Fix logic errors in the zero-inode path. (WebAssembly#352)
I've now tested the zero-inode path on a Wasm engine specially-modified to have `fd_readdir` set inode numbers to zero. Fix two bugs this turned up: - Increment `buffer_processed`, as noticed by @yamt - Don't do an `fstatat` on "..", because that references a path outside of the directory, which gets a permission-denied error.
1 parent a7f9938 commit a829eba

File tree

1 file changed

+2
-1
lines changed
  • libc-bottom-half/cloudlibc/src/libc/dirent

1 file changed

+2
-1
lines changed

libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ struct dirent *readdir(DIR *dirp) {
8989
// inode number.
9090
off_t d_ino = entry.d_ino;
9191
unsigned char d_type = entry.d_type;
92-
if (d_ino == 0) {
92+
if (d_ino == 0 && strcmp(dirent->d_name, "..") != 0) {
9393
struct stat statbuf;
9494
if (fstatat(dirp->fd, dirent->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) != 0) {
9595
if (errno == ENOENT) {
9696
// The file disappeared before we could read it, so skip it.
97+
dirp->buffer_processed += entry_size;
9798
continue;
9899
}
99100
return NULL;

0 commit comments

Comments
 (0)