Fix path_readlink: with a 0-sized buffer should succeed

This commit is contained in:
Jakub Konka
2019-06-13 22:46:46 +02:00
committed by Dan Gohman
parent 7fef91c1e4
commit dc05d89a08
2 changed files with 40 additions and 11 deletions

View File

@@ -580,16 +580,20 @@ pub fn path_readlink(
Ok(slice) => host_impl::path_from_raw(slice).to_owned(),
Err(e) => return enc_errno(e),
};
let rights = host::__WASI_RIGHT_PATH_READLINK;
let mut buf = match dec_slice_of_mut::<u8>(memory, buf_ptr, buf_len) {
Ok(slice) => slice,
Err(e) => return enc_errno(e),
};
let host_bufused =
match hostcalls_impl::path_readlink(wasi_ctx, dirfd, path.as_os_str(), rights, &mut buf) {
Ok(host_bufused) => host_bufused,
Err(e) => return enc_errno(e),
};
let host_bufused = match hostcalls_impl::path_readlink(
wasi_ctx,
dirfd,
path.as_os_str(),
host::__WASI_RIGHT_PATH_READLINK,
&mut buf,
) {
Ok(host_bufused) => host_bufused,
Err(e) => return enc_errno(e),
};
match enc_usize_byref(memory, buf_used, host_bufused) {
Ok(_) => wasm32::__WASI_ESUCCESS,
Err(e) => enc_errno(e),