Skip to content

Commit

Permalink
Fix logic errors in the zero-inode path. (#352)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sunfishcode authored Dec 6, 2022
1 parent 8098d86 commit 6cd1be1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ struct dirent *readdir(DIR *dirp) {
// inode number.
off_t d_ino = entry.d_ino;
unsigned char d_type = entry.d_type;
if (d_ino == 0) {
if (d_ino == 0 && strcmp(dirent->d_name, "..") != 0) {
struct stat statbuf;
if (fstatat(dirp->fd, dirent->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) != 0) {
if (errno == ENOENT) {
// The file disappeared before we could read it, so skip it.
dirp->buffer_processed += entry_size;
continue;
}
return NULL;
Expand Down

0 comments on commit 6cd1be1

Please sign in to comment.