-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use safe code for calling readlinkat
#519
Labels
Comments
This looks like a bug in nix. IIUC, the following line is the problem fn wrap_readlink_result(buffer: &mut[u8], res: ssize_t) -> Result<&OsStr> {
match Errno::result(res) {
Err(err) => Err(err),
Ok(len) => {
if (len as usize) >= buffer.len() { // *** This check ***
Err(Error::Sys(Errno::ENAMETOOLONG))
} else {
Ok(OsStr::from_bytes(&buffer[..(len as usize)]))
}
}
}
} In int main(int argc, const char * argv[]) {
std::string filename = "/tmp/test-dir/target";
size_t bufferSize = 9;
char* buffer = new char[bufferSize];
size_t rc = readlink (filename.c_str(), buffer, bufferSize);
// Since `readlink's` output depends on the `bufferSize`. If the`bufferSize` is 9 or greater than
// 9 then it will return 9 or else it will return `bufferSize` as the return value.
return 0;
} |
Created nix-rust/nix#1109 (hopefully that will fix the error). |
Nice one, thanks! |
marmistrz
referenced
this issue
in marmistrz/wasi-common
Aug 29, 2019
Currently, the fixed version of `readlinkat` is provided in upstream [nix](https://github.com/nix-rust/nix) crate only, therefore, we need to change `nix` to be a git dependency, which is not ideal. However, a new release should be out soon-ish, hence, I reckon it's OK to go with it as-is for now, and change to a semver when a new version gets released. Changes: * uses `nix::fcntl::readlinkat` instead of a direct call to `libc::readlinkat` * if read target path is longer than the buffer provided, pads the buffer with 0s
kubkon
added
enhancement
wasi:impl
Issues pertaining to WASI implementation in Wasmtime
labels
Nov 8, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On Linux,
readlinkat
returnsEINVAL
if given a zero-length buffer. WASI'swasi_path_readlink
should follow the POSIX semantics forreadlinkat
instead. wasi-common implements this, however it uses anunsafe
call to the libcreadlinkat
rather than calling through a safe nix wrapper.See the discussion here for more details.
The text was updated successfully, but these errors were encountered: