nodejs / uvwasi

WASI syscall API built atop libuv
MIT License
225 stars 49 forks source link

fix: Return correct length of string in fd_prestat_get #202

Closed ospencer closed 1 year ago

ospencer commented 1 year ago

Previously, fd_prestat_get would return the length of the directory name + 1, for the null terminator. This isn't quite right, as WASI strings are not null-terminated, and instead always operate in terms of a pointer and a size.

If a consumer of fd_prestat_get with fd_prestat_dir_name wants this value as a null-terminated string, they need to null-terminate it themselves, which I reflected in the tests.

This probably hasn't been noticed before because if the consumer of uvwasi uses null-terminated strings, functions like strlen will still report the correct value, but this isn't the case for languages that don't null-terminate strings, with null being a valid string character.

This could be considered a breaking fix if someone relied on uvwasi reporting and subsequently copying over the null byte, but I'll leave that decision to @cjihrig.