Skip to content

Fail to read link. #4873

Open
Open
@Userzxcvbvnm

Description

@Userzxcvbvnm

Describe the bug

Read bytes bug.

Steps to reproduce

(1)The test case is :


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

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_readlink_00001_xYCLW() {
    printf("Enter function path_readlink_00001_xYCLW\n");

    char link[100];
    ssize_t numBytes = readlinkat(AT_FDCWD, "softfile_1", link, 100);

    if (numBytes == -1) {
        printf("readlinkat\n");
    } else {
        link[numBytes] = '\0';
        printf("Symbolic link contents: %s\n", link);
    }
}

int main() {
    

    path_readlink_00001_xYCLW();

    

    return 0;
}


(2)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

(3)Running wasm:
(Before run the Wasm file, softfile_1 exists, softfile_1 is a softlink file points to subdir_1/subdir_1/subfile_2.)
wasmer run --dir=. test.wasm

Expected behavior

Print:

Enter function path_readlink_00001_xYCLW
Symbolic link contents: subdir_1/subdir_1/subfile_2

And this is what WAMR and wasmtime do.

Actual behavior

wasmer print:

Enter function path_readlink_00001_xYCLW
readlinkat

wasmer fails to read the source file of a softlink file.

Additional context

Ubuntu 20.04
x86_64
wasmer-4.3.1 and wasmer-4.2.2

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpriority-highHigh priority issue📦 lib-vfsAbout wasmer-vfs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions