bytecodealliance / bytecodealliance/wasmtime

Fail to create link file with AT_SYMLINK_FOLLOW parameter.

Open
#8,840 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

### Test Case
The c test case is:
```

#include
#include
#include
#include
#include

int get_fd(const char *filename, int flags) {
int fd = open(filename, flags);

if (fd == -1) {
printf("Get file descriptor of file %s failed!\n", filename);
return -1;
} else {
printf("Get file descriptor of file %s succeed!\n", filename);
return fd;
}
}

void closebyfd(int fd) {
if (close(fd) == -1) {
printf("Close the file %d by descriptor failed!\n", fd);
}
}

void path_link_00001_Nan21() {

printf("Enter function path_link_00001_Nan21\n");



int result = linkat(AT_FDCWD, "subdir_1/subdir_3/subfile_1", AT_FDCWD, "HARDLINKFILE", AT_SYMLINK_FOLLOW);

if (result == -1) {
printf("linkat failed");
} else {
printf("Hard link creation successful\n");
}


}

int main() {
printf("Enter function main\n");

path_link_00001_Nan21();

return 0;
}
```

### Steps to Reproduce
(1)compile to wasm:`./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm`

(2)Running wasm:
(Before run the Wasm file, file subdir_1/subdir_3/subfile_1 exists.)
`wasmtime run --dir=. test.wasm`

### Expected Results
Successfully create the link file and print:
```
Enter function main
Enter function path_link_00001_Nan21
Hard link creation successful
```

This is what WAMR and WasmEdge do.

### Actual Results
wasmtime prints:
```
Enter function main
Enter function path_link_00001_Nan21
linkat failed
```
However, with the parameter AT_SYMLINK_NOFOLLOW, wasmtime could cucceed, but with parameter AT_SYMLINK_FOLLOW, wasmtime fails.
The parameter AT_SYMLINK_FOLLOW means if the file subdir_1/subdir_3/subfile_1 is a softlink file, the file HARDLINKFILE is expected to points to the source file of subdir_1/subdir_3/subfile_1. In this case, subdir_1/subdir_3/subfile_1 is a not a softlink file, but, I think, in this way,it is expected that HARDLINKFILE points to subdir_1/subdir_3/subfile_1 directly.
I'm not sure whether this is a bug.

### Versions and Environment
Wasmtime version or commit: 19.0.2 and 13.0.1
Operating system: Ubuntu 20.04
Architecture: x86_64

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.