Skip to content

Commit e674332

Browse files
committed
fuzz: use process::exit panic hook in stdin_fuzz to avoid macOS hang
On macOS, panic=abort causes the process to call abort() which sends SIGABRT. The ReportCrash daemon then tries to generate a crash report, leaving the process stuck in an uninterruptible wait state that cannot be killed even with SIGKILL. This makes stdin_fuzz unusable for crash reproduction on macOS. Install a custom panic hook that flushes stdout (preserving log output), prints the panic info with a full backtrace to stderr, then calls process::exit(1) to terminate cleanly before the abort machinery runs. The hook has zero overhead during normal execution since it is only invoked when a panic occurs. AI tools were used in preparing this commit.
1 parent ec03159 commit e674332

File tree

72 files changed

+792
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+792
-0
lines changed

fuzz/src/bin/base32_target.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ fuzz_target!(|data: &[u8]| {
5757
fn main() {
5858
use std::io::Read;
5959

60+
// On macOS, panic=abort causes the process to send SIGABRT which can leave it
61+
// stuck in an uninterruptible state due to the ReportCrash daemon. Using
62+
// process::exit in a panic hook avoids this by terminating cleanly.
63+
std::panic::set_hook(Box::new(|panic_info| {
64+
use std::io::Write;
65+
let _ = std::io::stdout().flush();
66+
eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture());
67+
let _ = std::io::stderr().flush();
68+
std::process::exit(1);
69+
}));
70+
6071
let mut data = Vec::with_capacity(8192);
6172
std::io::stdin().read_to_end(&mut data).unwrap();
6273
base32_test(&data, lightning_fuzz::utils::test_logger::Stdout {});

fuzz/src/bin/bech32_parse_target.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ fuzz_target!(|data: &[u8]| {
5757
fn main() {
5858
use std::io::Read;
5959

60+
// On macOS, panic=abort causes the process to send SIGABRT which can leave it
61+
// stuck in an uninterruptible state due to the ReportCrash daemon. Using
62+
// process::exit in a panic hook avoids this by terminating cleanly.
63+
std::panic::set_hook(Box::new(|panic_info| {
64+
use std::io::Write;
65+
let _ = std::io::stdout().flush();
66+
eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture());
67+
let _ = std::io::stderr().flush();
68+
std::process::exit(1);
69+
}));
70+
6071
let mut data = Vec::with_capacity(8192);
6172
std::io::stdin().read_to_end(&mut data).unwrap();
6273
bech32_parse_test(&data, lightning_fuzz::utils::test_logger::Stdout {});

fuzz/src/bin/bolt11_deser_target.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ fuzz_target!(|data: &[u8]| {
5757
fn main() {
5858
use std::io::Read;
5959

60+
// On macOS, panic=abort causes the process to send SIGABRT which can leave it
61+
// stuck in an uninterruptible state due to the ReportCrash daemon. Using
62+
// process::exit in a panic hook avoids this by terminating cleanly.
63+
std::panic::set_hook(Box::new(|panic_info| {
64+
use std::io::Write;
65+
let _ = std::io::stdout().flush();
66+
eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture());
67+
let _ = std::io::stderr().flush();
68+
std::process::exit(1);
69+
}));
70+
6071
let mut data = Vec::with_capacity(8192);
6172
std::io::stdin().read_to_end(&mut data).unwrap();
6273
bolt11_deser_test(&data, lightning_fuzz::utils::test_logger::Stdout {});

fuzz/src/bin/chanmon_consistency_target.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ fuzz_target!(|data: &[u8]| {
5757
fn main() {
5858
use std::io::Read;
5959

60+
// On macOS, panic=abort causes the process to send SIGABRT which can leave it
61+
// stuck in an uninterruptible state due to the ReportCrash daemon. Using
62+
// process::exit in a panic hook avoids this by terminating cleanly.
63+
std::panic::set_hook(Box::new(|panic_info| {
64+
use std::io::Write;
65+
let _ = std::io::stdout().flush();
66+
eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture());
67+
let _ = std::io::stderr().flush();
68+
std::process::exit(1);
69+
}));
70+
6071
let mut data = Vec::with_capacity(8192);
6172
std::io::stdin().read_to_end(&mut data).unwrap();
6273
chanmon_consistency_test(&data, lightning_fuzz::utils::test_logger::Stdout {});

fuzz/src/bin/chanmon_deser_target.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ fuzz_target!(|data: &[u8]| {
5757
fn main() {
5858
use std::io::Read;
5959

60+
// On macOS, panic=abort causes the process to send SIGABRT which can leave it
61+
// stuck in an uninterruptible state due to the ReportCrash daemon. Using
62+
// process::exit in a panic hook avoids this by terminating cleanly.
63+
std::panic::set_hook(Box::new(|panic_info| {
64+
use std::io::Write;
65+
let _ = std::io::stdout().flush();
66+
eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture());
67+
let _ = std::io::stderr().flush();
68+
std::process::exit(1);
69+
}));
70+
6071
let mut data = Vec::with_capacity(8192);
6172
std::io::stdin().read_to_end(&mut data).unwrap();
6273
chanmon_deser_test(&data, lightning_fuzz::utils::test_logger::Stdout {});

fuzz/src/bin/feature_flags_target.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ fuzz_target!(|data: &[u8]| {
5757
fn main() {
5858
use std::io::Read;
5959

60+
// On macOS, panic=abort causes the process to send SIGABRT which can leave it
61+
// stuck in an uninterruptible state due to the ReportCrash daemon. Using
62+
// process::exit in a panic hook avoids this by terminating cleanly.
63+
std::panic::set_hook(Box::new(|panic_info| {
64+
use std::io::Write;
65+
let _ = std::io::stdout().flush();
66+
eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture());
67+
let _ = std::io::stderr().flush();
68+
std::process::exit(1);
69+
}));
70+
6071
let mut data = Vec::with_capacity(8192);
6172
std::io::stdin().read_to_end(&mut data).unwrap();
6273
feature_flags_test(&data, lightning_fuzz::utils::test_logger::Stdout {});

fuzz/src/bin/fromstr_to_netaddress_target.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ fuzz_target!(|data: &[u8]| {
5757
fn main() {
5858
use std::io::Read;
5959

60+
// On macOS, panic=abort causes the process to send SIGABRT which can leave it
61+
// stuck in an uninterruptible state due to the ReportCrash daemon. Using
62+
// process::exit in a panic hook avoids this by terminating cleanly.
63+
std::panic::set_hook(Box::new(|panic_info| {
64+
use std::io::Write;
65+
let _ = std::io::stdout().flush();
66+
eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture());
67+
let _ = std::io::stderr().flush();
68+
std::process::exit(1);
69+
}));
70+
6071
let mut data = Vec::with_capacity(8192);
6172
std::io::stdin().read_to_end(&mut data).unwrap();
6273
fromstr_to_netaddress_test(&data, lightning_fuzz::utils::test_logger::Stdout {});

fuzz/src/bin/fs_store_target.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ fuzz_target!(|data: &[u8]| {
5757
fn main() {
5858
use std::io::Read;
5959

60+
// On macOS, panic=abort causes the process to send SIGABRT which can leave it
61+
// stuck in an uninterruptible state due to the ReportCrash daemon. Using
62+
// process::exit in a panic hook avoids this by terminating cleanly.
63+
std::panic::set_hook(Box::new(|panic_info| {
64+
use std::io::Write;
65+
let _ = std::io::stdout().flush();
66+
eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture());
67+
let _ = std::io::stderr().flush();
68+
std::process::exit(1);
69+
}));
70+
6071
let mut data = Vec::with_capacity(8192);
6172
std::io::stdin().read_to_end(&mut data).unwrap();
6273
fs_store_test(&data, lightning_fuzz::utils::test_logger::Stdout {});

fuzz/src/bin/full_stack_target.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ fuzz_target!(|data: &[u8]| {
5757
fn main() {
5858
use std::io::Read;
5959

60+
// On macOS, panic=abort causes the process to send SIGABRT which can leave it
61+
// stuck in an uninterruptible state due to the ReportCrash daemon. Using
62+
// process::exit in a panic hook avoids this by terminating cleanly.
63+
std::panic::set_hook(Box::new(|panic_info| {
64+
use std::io::Write;
65+
let _ = std::io::stdout().flush();
66+
eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture());
67+
let _ = std::io::stderr().flush();
68+
std::process::exit(1);
69+
}));
70+
6071
let mut data = Vec::with_capacity(8192);
6172
std::io::stdin().read_to_end(&mut data).unwrap();
6273
full_stack_test(&data, lightning_fuzz::utils::test_logger::Stdout {});

fuzz/src/bin/indexedmap_target.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ fuzz_target!(|data: &[u8]| {
5757
fn main() {
5858
use std::io::Read;
5959

60+
// On macOS, panic=abort causes the process to send SIGABRT which can leave it
61+
// stuck in an uninterruptible state due to the ReportCrash daemon. Using
62+
// process::exit in a panic hook avoids this by terminating cleanly.
63+
std::panic::set_hook(Box::new(|panic_info| {
64+
use std::io::Write;
65+
let _ = std::io::stdout().flush();
66+
eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture());
67+
let _ = std::io::stderr().flush();
68+
std::process::exit(1);
69+
}));
70+
6071
let mut data = Vec::with_capacity(8192);
6172
std::io::stdin().read_to_end(&mut data).unwrap();
6273
indexedmap_test(&data, lightning_fuzz::utils::test_logger::Stdout {});

0 commit comments

Comments
 (0)