From ab2e0a465e4eafe4de2cc6ac7ef61d1655db4c2d Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 7 Oct 2021 20:33:00 +0530 Subject: [PATCH] fix(ext/ffi): don't panic in dlopen (#12344) --- ext/ffi/lib.rs | 8 ++++++-- test_ffi/tests/integration_tests.rs | 1 + test_ffi/tests/test.js | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs index b5505fb0cf..d2b0d24df5 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -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::(); 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, diff --git a/test_ffi/tests/integration_tests.rs b/test_ffi/tests/integration_tests.rs index 0ae395da86..28176f1876 100644 --- a/test_ffi/tests/integration_tests.rs +++ b/test_ffi/tests/integration_tests.rs @@ -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\ diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js index fc354139da..098541265c 100644 --- a/test_ffi/tests/test.js +++ b/test_ffi/tests/test.js @@ -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" },