Skip to content
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

fix(ext/ffi): Check CStr for UTF-8 validity on read #15318

Merged
merged 14 commits into from
Aug 5, 2022
Prev Previous commit
Next Next commit
Update ext/ffi/lib.rs
Co-authored-by: Phosra <[email protected]>
  • Loading branch information
aapoalas and Phosra authored Jul 28, 2022
commit 195e68547d2b20adc35b44e9fbedbd0f9d168357
5 changes: 2 additions & 3 deletions ext/ffi/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2144,10 +2144,9 @@ where
// SAFETY: Pointer is user provided.
let cstr = unsafe { CStr::from_ptr(ptr as *const c_char) }
.to_str()
.map_err(|_| type_error("Invalid CString pointer, not valid UTF-8"))?
.as_bytes();
.map_err(|_| type_error("Invalid CString pointer, not valid UTF-8"))?;
let value: v8::Local<v8::Value> =
v8::String::new_from_utf8(scope, cstr, v8::NewStringType::Normal)
v8::String::new(scope, cstr)
.ok_or_else(|| {
type_error("Invalid CString pointer, string exceeds max length")
})?
Expand Down