From 689fce307911b4cebac8114c122bc5149c8d3766 Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Mon, 14 Jun 2004 17:26:35 +0000 Subject: [PATCH] print a fancy message when SIGSEGV is caught at the decompression --- lib/lizard.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/lizard.c b/lib/lizard.c index 3968a710..ad1a7897 100644 --- a/lib/lizard.c +++ b/lib/lizard.c @@ -15,6 +15,7 @@ #include #include #include +#include typedef u16 hash_ptr_t; struct hash_record { @@ -419,6 +420,12 @@ lizard_free(struct lizard_buffer *buf) xfree(buf); } +static void +sigsegv_handler(int UNUSED whatsit) +{ + die("SIGSEGV caught when decompressing."); +} + int lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length) /* Decompresses into buf->ptr and returns the length of the uncompressed @@ -430,7 +437,10 @@ lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length) return -1; mprotect(buf->ptr, lock_offset, PROT_READ | PROT_WRITE); mprotect(buf->ptr + lock_offset, PAGE_SIZE, PROT_READ); - return lizard_decompress(in, buf->ptr); + sighandler_t old_handler = signal(SIGSEGV, sigsegv_handler); + int len = lizard_decompress(in, buf->ptr); + signal(SIGSEGV, old_handler); + return len; } /* -- 2.39.5