Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is being able to open and stat a directory intended? #3203

Closed
zzjas opened this issue Sep 28, 2022 · 4 comments
Closed

Is being able to open and stat a directory intended? #3203

zzjas opened this issue Sep 28, 2022 · 4 comments
Labels
bug Something isn't working 📦 lib-wasi About wasmer-wasi priority-medium Medium priority issue 🏚 stale Inactive issues or PR

Comments

@zzjas
Copy link

zzjas commented Sep 28, 2022

Describe the bug

Wasmer is able to open and stat a directory when the flag is O_RDWR.

#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

int main(int argc, char * argv[]) {
	int fd0 = open("test_dir", O_RDWR);
	printf("fd is %d\n", fd0);
	struct stat stat;
        stat.st_size = 0;
	fstat(fd0, &stat);
	printf("stat dir size %d\n", stat.st_size);
}

Steps to reproduce

Store the above into a file dir.c.
Compile with wasi-sdk-16.0 and run with wasmer.

mkdir -p test_dir
$WASI_SDK_PATH/bin/clang --sysroot=$WASI_SDK_PATH/share/wasi-sysroot dir.c -o dir.wasm
wasmer dir.wasm --dir=.

To compare:

wasmtime dir.wasm --dir=.
clang dir.c -o dir.out
./dir.out

Expected behavior

The open returns -1.

Actual behavior

open returns a file descriptor and it can be used to stat.

@zzjas zzjas added the bug Something isn't working label Sep 28, 2022
@fschutt
Copy link
Contributor

fschutt commented Sep 28, 2022

I think this is a duplicate of #3125, which is currently being worked on in #3201.

@zzjas
Copy link
Author

zzjas commented Sep 28, 2022

Hi, thanks for checking out the issue. I'm not sure if they are the same. #3125 was about rights for an existing file descriptor. However, here a valid file descriptor should not be returned by open in the first place.

e.g.
Here is the output from wasmer

fd is 5
stat dir size 128

and here is the output from wasmtime and native libc

fd is -1
stat dir size 0

I built wasmer on branchwasi-fs-rights commit 00ad13810869d9e07466209f4bdd686409e631a2 from #3201 with make build-wasmer. The behavior of open is still the same as described above.

@stale
Copy link

stale bot commented Sep 30, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the 🏚 stale Inactive issues or PR label Sep 30, 2023
@stale
Copy link

stale bot commented Oct 31, 2023

Feel free to reopen the issue if it has been closed by mistake.

@stale stale bot closed this as completed Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-wasi About wasmer-wasi priority-medium Medium priority issue 🏚 stale Inactive issues or PR
Projects
None yet
Development

No branches or pull requests

3 participants