1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-27 16:10:57 -05:00

fix(signals): prevent panic when listening to forbidden signals (#13273)

This commit is contained in:
Leo Kettmeir 2022-01-04 21:55:06 +01:00 committed by Bartek Iwańczuk
parent 8a10f4bfcb
commit d69091a4e7
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
4 changed files with 43 additions and 1 deletions

1
Cargo.lock generated
View file

@ -942,6 +942,7 @@ dependencies = [
"regex",
"ring",
"serde",
"signal-hook-registry",
"sys-info",
"termcolor",
"test_util",

View file

@ -203,3 +203,37 @@ Deno.test(
});
},
);
Deno.test(
{
ignore: Deno.build.os === "windows",
permissions: { run: true },
},
function signalForbiddenSignalTest() {
assertThrows(
() => Deno.addSignalListener("SIGKILL", () => {}),
TypeError,
"Binding to signal 'SIGKILL' is not allowed",
);
assertThrows(
() => Deno.addSignalListener("SIGSTOP", () => {}),
TypeError,
"Binding to signal 'SIGSTOP' is not allowed",
);
assertThrows(
() => Deno.addSignalListener("SIGILL", () => {}),
TypeError,
"Binding to signal 'SIGILL' is not allowed",
);
assertThrows(
() => Deno.addSignalListener("SIGFPE", () => {}),
TypeError,
"Binding to signal 'SIGFPE' is not allowed",
);
assertThrows(
() => Deno.addSignalListener("SIGSEGV", () => {}),
TypeError,
"Binding to signal 'SIGSEGV' is not allowed",
);
},
);

View file

@ -75,6 +75,7 @@ once_cell = "=1.9.0"
regex = "1.5.4"
ring = "0.16.20"
serde = { version = "1.0.129", features = ["derive"] }
signal-hook-registry = "1.4.0"
sys-info = "0.9.0"
termcolor = "1.1.2"
tokio = { version = "1.10.1", features = ["full"] }

View file

@ -181,8 +181,14 @@ fn op_signal_bind(
) -> Result<ResourceId, AnyError> {
super::check_unstable(state, "Deno.signal");
let signo = signal_str_to_int(&sig)?;
if signal_hook_registry::FORBIDDEN.contains(&signo) {
return Err(type_error(format!(
"Binding to signal '{}' is not allowed",
sig
)));
}
let resource = SignalStreamResource {
signal: AsyncRefCell::new(signal(SignalKind::from_raw(signo)).unwrap()),
signal: AsyncRefCell::new(signal(SignalKind::from_raw(signo))?),
cancel: Default::default(),
};
let rid = state.resource_table.add(resource);