Skip to content

readdir() can't return absolute symlinks #5143

Open
@kkebo

Description

@kkebo

Describe the bug

readdir() can't return absolute symlinks.

$ wasmer -vV; rustc -vV
wasmer 4.4.0 (b2fa4b1 2024-10-05)
binary: wasmer-cli
commit-hash: b2fa4b19ff24f2facbe878b256c76d8e4bd6b25a
commit-date: 2024-10-05
host: aarch64-unknown-linux-gnu
compiler: singlepass,cranelift
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: aarch64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

Steps to reproduce

  1. cargo new readdir-test
  2. cd readdir-test
  3. cargo add libc
  4. Edit src/main.rs
    use libc::{opendir, readdir};
    use std::ffi::CStr;
    
    fn main() {
        unsafe {
            let dp = opendir(b"/tmp/test\x00" as *const u8 as *const i8);
            assert!(!dp.is_null());
            loop {
                let ent = readdir(dp);
                if ent.is_null() {
                    break;
                }
                let name = CStr::from_ptr((*ent).d_name.as_ptr());
                println!("{:?}", name);
            }
        }
    }
  5. mkdir /tmp/test
  6. touch /tmp/test/a
  7. touch /tmp/test/b
  8. ln -s /tmp/test/b /tmp/test/c
  9. cargo build --target wasm32-wasip1 (before that, you need to run rustup target add wasm32-wasip1)
  10. wasmer run --mapdir /tmp/test:/tmp/test target/wasm32-wasip1/debug/readdir-test.wasm

Expected behavior

"."
".."
"a"
"b"
"c"

Actual behavior

"."
".."
"a"
"b"

Additional context

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinglib-wasixIssues related to the WASIX toolchain.priority-mediumMedium priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions