mirror of
https://github.com/denoland/deno.git
synced 2024-11-30 16:40:57 -05:00
fix(signals): prevent panic when listening to forbidden signals (#13273)
This commit is contained in:
parent
8a10f4bfcb
commit
d69091a4e7
4 changed files with 43 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -942,6 +942,7 @@ dependencies = [
|
|||
"regex",
|
||||
"ring",
|
||||
"serde",
|
||||
"signal-hook-registry",
|
||||
"sys-info",
|
||||
"termcolor",
|
||||
"test_util",
|
||||
|
|
|
@ -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",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -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"] }
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue