[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-hackers] [PATCH] fix incorrect type of jmp_buf
From: |
Felix |
Subject: |
[Chicken-hackers] [PATCH] fix incorrect type of jmp_buf |
Date: |
Mon, 17 Jun 2013 09:06:11 +0200 (CEST) |
The attached patch fixes a bug in the runtime system: when
sigsetjmp(3) is used, then "C_restart" and "gc_restart" must be of
type "sigjmp_buf". Currently they are still declared as "jmp_buf",
which in most cases will be smaller than a "sigjmp_buf", resulting in
overwritten memory once a "jmp_buf" is set up.
This is quite a serious bug, and I recommend putting the patch into
the stability branch.
cheers,
felix
>From ecd4b3a6f2e1f5076de0163b3d1758a7b577315e Mon Sep 17 00:00:00 2001
From: felix <address@hidden>
Date: Sun, 16 Jun 2013 00:04:55 +0200
Subject: [PATCH] If sigsetjmp(3) is used, "gc_restart" must be of the correct
type.
---
chicken.h | 4 ++++
runtime.c | 16 ++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/chicken.h b/chicken.h
index ce54b3c..fb7418e 100644
--- a/chicken.h
+++ b/chicken.h
@@ -1591,7 +1591,11 @@ C_varextern C_TLS C_long
C_varextern C_TLS C_byte
*C_fromspace_top,
*C_fromspace_limit;
+#ifdef HAVE_SIGSETJMP
+C_varextern C_TLS sigjmp_buf C_restart;
+#else
C_varextern C_TLS jmp_buf C_restart;
+#endif
C_varextern C_TLS void *C_restart_address;
C_varextern C_TLS int C_entry_point_status;
C_varextern C_TLS int C_gui_mode;
diff --git a/runtime.c b/runtime.c
index 5ce267e..689c079 100644
--- a/runtime.c
+++ b/runtime.c
@@ -334,7 +334,11 @@ C_TLS C_long
C_TLS C_byte
*C_fromspace_top,
*C_fromspace_limit;
+#ifdef HAVE_SIGSETJMP
+C_TLS sigjmp_buf C_restart;
+#else
C_TLS jmp_buf C_restart;
+#endif
C_TLS void *C_restart_address;
C_TLS int C_entry_point_status;
C_TLS int (*C_gc_mutation_hook)(C_word *slot, C_word val);
@@ -442,7 +446,11 @@ static C_TLS unsigned int
mutation_count,
stack_size;
static C_TLS int chicken_is_initialized;
+#ifdef HAVE_SIGSETJMP
+static C_TLS sigjmp_buf gc_restart;
+#else
static C_TLS jmp_buf gc_restart;
+#endif
static C_TLS double
timer_start_ms,
gc_ms,
@@ -1917,7 +1925,11 @@ C_word C_fcall C_callback(C_word closure, int argc)
if(old && C_block_item(callback_continuation_stack_symbol, 0) ==
C_SCHEME_END_OF_LIST)
panic(C_text("callback invoked in non-safe context"));
+#ifdef HAVE_SIGSETJMP
+ C_memcpy(&prev, &C_restart, sizeof(sigjmp_buf));
+#else
C_memcpy(&prev, &C_restart, sizeof(jmp_buf));
+#endif
callback_returned_flag = 0;
chicken_is_running = 1;
@@ -1931,7 +1943,11 @@ C_word C_fcall C_callback(C_word closure, int argc)
if(!callback_returned_flag) (C_restart_trampoline)(C_restart_address);
else {
+#ifdef HAVE_SIGSETJMP
+ C_memcpy(&C_restart, &prev, sizeof(sigjmp_buf));
+#else
C_memcpy(&C_restart, &prev, sizeof(jmp_buf));
+#endif
callback_returned_flag = 0;
}
--
1.7.9.5
- [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf,
Felix <=
- Re: [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf, Peter Bex, 2013/06/17
- Re: [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf, Felix, 2013/06/17
- Re: [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf, Jim Ursetto, 2013/06/17
- Re: [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf, Jörg F . Wittenberger, 2013/06/18
- Re: [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf, Peter Bex, 2013/06/18
- Re: [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf, Jörg F . Wittenberger, 2013/06/18
- Re: [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf, Peter Bex, 2013/06/18
- Re: [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf, Jörg F . Wittenberger, 2013/06/19
- Re: [Chicken-hackers] [PATCH] fix incorrect type of jmp_buf, Peter Bex, 2013/06/21