1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 08:09:08 -05:00

fix(ext/ffi): don't panic in dlopen (#12344)

This commit is contained in:
Divy Srivastava 2021-10-07 20:33:00 +05:30 committed by GitHub
parent 822047b845
commit ab2e0a465e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View file

@ -1,6 +1,5 @@
// Copyright 2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::anyhow;
use deno_core::error::bad_resource_id;
use deno_core::error::AnyError;
use deno_core::include_js_files;
@ -370,7 +369,12 @@ where
let permissions = state.borrow_mut::<FP>();
permissions.check(&path)?;
let lib = Library::open(&path).map_err(|e| anyhow!(format_error(e, path)))?;
let lib = Library::open(&path).map_err(|e| {
dlopen::Error::OpeningLibraryError(std::io::Error::new(
std::io::ErrorKind::Other,
format_error(e, path),
))
})?;
let mut resource = DynamicLibraryResource {
lib,

View file

@ -37,6 +37,7 @@ fn basic() {
println!("{:?}", output.status);
assert!(output.status.success());
let expected = "\
dlopen doesn't panic\n\
something\n\
[1, 2, 3, 4, 5, 6, 7, 8]\n\
579\n\

View file

@ -10,6 +10,14 @@ const [libPrefix, libSuffix] = {
const libPath = `${targetDir}/${libPrefix}test_ffi.${libSuffix}`;
const resourcesPre = Deno.resources();
// dlopen shouldn't panic
try {
Deno.dlopen("cli/src/main.rs", {});
} catch (_) {
console.log("dlopen doesn't panic");
}
const dylib = Deno.dlopen(libPath, {
"print_something": { parameters: [], result: "void" },
"print_buffer": { parameters: ["buffer", "usize"], result: "void" },