Merge pull request #290 from real-or-random/202103_panic_from_c
Manually test that panicking from C will abort the process
This commit is contained in:
commit
63f4de78ce
|
@ -78,6 +78,9 @@ if [ "$DO_ASAN" = true ]; then
|
||||||
cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully"
|
cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Test if panic in C code aborts the process (either with a real panic or with SIGILL)
|
||||||
|
cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 | tee /dev/stderr | grep "SIGILL\\|panicked at '\[libsecp256k1\]"
|
||||||
|
|
||||||
# Bench
|
# Bench
|
||||||
if [ "$DO_BENCH" = true ]; then
|
if [ "$DO_BENCH" = true ]; then
|
||||||
cargo bench --all --features="unstable"
|
cargo bench --all --features="unstable"
|
||||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -938,14 +938,12 @@ mod tests {
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic]
|
#[ignore] // Panicking from C may trap (SIGILL) intentionally, so we test this manually.
|
||||||
fn test_panic_raw_ctx() {
|
fn test_panic_raw_ctx_should_terminate_abnormally() {
|
||||||
let ctx_vrfy = Secp256k1::verification_only();
|
let ctx_vrfy = Secp256k1::verification_only();
|
||||||
let raw_ctx_verify_as_full = unsafe {Secp256k1::from_raw_all(ctx_vrfy.ctx)};
|
let raw_ctx_verify_as_full = unsafe {Secp256k1::from_raw_all(ctx_vrfy.ctx)};
|
||||||
let (sk, _) = raw_ctx_verify_as_full.generate_keypair(&mut thread_rng());
|
// Generating a key pair in verify context will panic (ARG_CHECK).
|
||||||
let msg = Message::from_slice(&[2u8; 32]).unwrap();
|
raw_ctx_verify_as_full.generate_keypair(&mut thread_rng());
|
||||||
// Try signing
|
|
||||||
raw_ctx_verify_as_full.sign(&msg, &sk);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue