summaryrefslogtreecommitdiff
path: root/darwin_stop_world.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-12-11 23:18:18 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-12-11 23:18:18 +0300
commit128c0ec33dc7b41c1ea40ca27d57821135744182 (patch)
tree38d482b6fd10341d89c0659d2f3f55179b352840 /darwin_stop_world.c
parent8fd5c0d9787c1bc01d45964014e866d3a3f8ddf5 (diff)
downloadbdwgc-128c0ec33dc7b41c1ea40ca27d57821135744182.tar.gz
Fix possible null pointer dereference in GC_stack_range_for
(fix of commit 7eb49a4e6) Issue #362 (bdwgc). * darwin_stop_world.c (GC_stack_range_for): Do not set crtn local variable value until p is guaranteed to be non-NULL (i.e., do not set crtn value unless DARWIN_DONT_PARSE_STACK).
Diffstat (limited to 'darwin_stop_world.c')
-rw-r--r--darwin_stop_world.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/darwin_stop_world.c b/darwin_stop_world.c
index 5debf480..53824970 100644
--- a/darwin_stop_world.c
+++ b/darwin_stop_world.c
@@ -142,7 +142,7 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p,
mach_port_t my_thread, ptr_t *paltstack_lo,
ptr_t *paltstack_hi, GC_bool *pfound_me)
{
- GC_stack_context_t crtn = p -> crtn;
+ GC_stack_context_t crtn;
ptr_t lo;
if (thread == my_thread) {
@@ -153,9 +153,9 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p,
# endif
*pfound_me = TRUE;
} else if (p != NULL && (p -> flags & DO_BLOCKING) != 0) {
- lo = crtn -> stack_ptr;
+ lo = p -> crtn -> stack_ptr;
# ifndef DARWIN_DONT_PARSE_STACK
- *phi = crtn -> topOfStack;
+ *phi = p -> crtn -> topOfStack;
# endif
} else {
@@ -327,6 +327,7 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p,
UNUSED_ARG(paltstack_hi);
# else
/* p is guaranteed to be non-NULL regardless of GC_query_task_threads. */
+ crtn = p -> crtn;
*phi = EXPECT((p -> flags & MAIN_THREAD) == 0, TRUE) ? crtn -> stack_end
: GC_stackbottom;
if (crtn -> altstack != NULL && (word)(crtn -> altstack) <= (word)lo