Return __WASI_EINVAL from fd_prestat_dir_name (#2580)

Return a WASI error code (rather than a host POSIX one). In addition,
there is no need to return an error in the case that the provided buffer
is too large.
This commit is contained in:
zoraaver 2023-09-25 11:40:12 +01:00 committed by GitHub
parent 363f08975b
commit f474f3d668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -819,12 +819,14 @@ wasmtime_ssp_fd_prestat_dir_name(struct fd_prestats *prestats, __wasi_fd_t fd,
rwlock_unlock(&prestats->lock);
return error;
}
if (path_len != strlen(prestat->dir)) {
const size_t prestat_dir_len = strlen(prestat->dir);
if (path_len < prestat_dir_len) {
rwlock_unlock(&prestats->lock);
return EINVAL;
return __WASI_EINVAL;
}
bh_memcpy_s(path, (uint32)path_len, prestat->dir, (uint32)path_len);
bh_memcpy_s(path, (uint32)path_len, prestat->dir, (uint32)prestat_dir_len);
rwlock_unlock(&prestats->lock);