nodejs / uvwasi

WASI syscall API built atop libuv
MIT License
226 stars 50 forks source link

uvwasi_fd_readdir returns garbage for dirent names #148

Closed chjj closed 4 years ago

chjj commented 4 years ago

Reproducible with any call to readdir or scandir from wasi-libc.

I believe the issue is this line: https://github.com/cjihrig/uvwasi/blob/d3fe61d/src/uvwasi.c#L1392

      /* Write the entry name to the buffer. */
      available = buf_len - *bufused;
      size_to_cp = name_len > available ? available : name_len;
      memcpy((char*)buf + *bufused, &dirents[i].name, size_to_cp); // bad memcpy
      *bufused += size_to_cp;

It appears uvwasi is calling memcpy on a pointer to the name string, not the string itself.