From 8a4a349ebe5a24fd2afefea8c53672433b756a91 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Sat, 24 Jul 2004 17:35:24 +0000 Subject: 2004-07-24 Joel Sherrill PR 660/rtems * score/cpu/m68k/rtems/score/m68k.h, score/cpu/mips/cpu_asm.S, score/src/threadinitialize.c, score/src/threadstackallocate.c: Check for overflow when allocating stack. --- cpukit/ChangeLog | 7 +++++++ cpukit/score/src/threadinitialize.c | 2 +- cpukit/score/src/threadstackallocate.c | 22 +++++++++++----------- 3 files changed, 19 insertions(+), 12 deletions(-) (limited to 'cpukit') diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 61e345aac6..f9442718be 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,10 @@ +2004-07-24 Joel Sherrill + + PR 660/rtems + * score/cpu/m68k/rtems/score/m68k.h, score/cpu/mips/cpu_asm.S, + score/src/threadinitialize.c, score/src/threadstackallocate.c: Check + for overflow when allocating stack. + 2004-07-24 Joel Sherrill PR 659/rtems diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c index f319fc73d9..9a3649865d 100644 --- a/cpukit/score/src/threadinitialize.c +++ b/cpukit/score/src/threadinitialize.c @@ -76,7 +76,7 @@ boolean _Thread_Initialize( actual_stack_size = _Thread_Stack_Allocate( the_thread, actual_stack_size ); - if ( !actual_stack_size ) + if ( !actual_stack_size || actual_stack_size < stack_size ) return FALSE; /* stack allocation failed */ stack = the_thread->Start.stack; diff --git a/cpukit/score/src/threadstackallocate.c b/cpukit/score/src/threadstackallocate.c index 74872d91f5..6709ee22ba 100644 --- a/cpukit/score/src/threadstackallocate.c +++ b/cpukit/score/src/threadstackallocate.c @@ -36,15 +36,16 @@ * Set the Start.stack field to the address of the stack */ -uint32_t _Thread_Stack_Allocate( +uint32_t _Thread_Stack_Allocate( Thread_Control *the_thread, - uint32_t stack_size + uint32_t stack_size ) { void *stack_addr = 0; + uint32_t the_stack_size = stack_size; - if ( !_Stack_Is_enough( stack_size ) ) - stack_size = STACK_MINIMUM_SIZE; + if ( !_Stack_Is_enough( the_stack_size ) ) + the_stack_size = STACK_MINIMUM_SIZE; /* * Call ONLY the CPU table stack allocate hook, _or_ the @@ -52,9 +53,8 @@ uint32_t _Thread_Stack_Allocate( * routine can call the correct deallocation routine. */ - if ( _CPU_Table.stack_allocate_hook ) - { - stack_addr = (*_CPU_Table.stack_allocate_hook)( stack_size ); + if ( _CPU_Table.stack_allocate_hook ) { + stack_addr = (*_CPU_Table.stack_allocate_hook)( the_stack_size ); } else { /* @@ -68,14 +68,14 @@ uint32_t _Thread_Stack_Allocate( * the context initialization sequence in sync. */ - stack_size = _Stack_Adjust_size( stack_size ); - stack_addr = _Workspace_Allocate( stack_size ); + the_stack_size = _Stack_Adjust_size( the_stack_size ); + stack_addr = _Workspace_Allocate( the_stack_size ); } if ( !stack_addr ) - stack_size = 0; + the_stack_size = 0; the_thread->Start.stack = stack_addr; - return stack_size; + return the_stack_size; } -- cgit v1.2.3