score: Fix _Stack_Extend_size()

Check for an integer overflow.  Add a validation test for task create
errors.
This commit is contained in:
Sebastian Huber
2021-02-26 12:34:21 +01:00
parent 9dad735697
commit 08cbd4ba20
3 changed files with 3202 additions and 7 deletions

View File

@@ -119,28 +119,42 @@ RTEMS_INLINE_ROUTINE size_t _Stack_Ensure_minimum (
} }
/** /**
* @brief Extend the stack size to account for additional data structures * @brief Extends the stack size to account for additional data structures
* allocated in the stack area of a thread. * allocated in the thread storage area.
* *
* @param stack_size The stack size. * @param stack_size is the stack size.
* @param is_fp Indicates if the stack is for a floating-point thread.
* *
* @return The extended stack size. * @param is_fp shall be true, if the stack is for a floating-point thread,
* otherwise it shall be false.
*
* @return Returns the extended stack size.
*/ */
RTEMS_INLINE_ROUTINE size_t _Stack_Extend_size( RTEMS_INLINE_ROUTINE size_t _Stack_Extend_size(
size_t stack_size, size_t stack_size,
bool is_fp bool is_fp
) )
{ {
size_t extra_size;
extra_size = _TLS_Get_allocation_size();
#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE ) #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
if ( is_fp ) { if ( is_fp ) {
stack_size += CONTEXT_FP_SIZE; /* This addition cannot overflow since the TLS size cannot be that large */
extra_size += CONTEXT_FP_SIZE;
} }
#else #else
(void) is_fp; (void) is_fp;
#endif #endif
stack_size += _TLS_Get_allocation_size(); stack_size += extra_size;
if ( stack_size < extra_size ) {
/*
* In case of an unsigned integer overflow, saturate at the maximum value.
*/
stack_size = SIZE_MAX;
}
return stack_size; return stack_size;
} }

View File

@@ -20,6 +20,7 @@ source:
- testsuites/validation/tc-signal-catch.c - testsuites/validation/tc-signal-catch.c
- testsuites/validation/tc-signal-send.c - testsuites/validation/tc-signal-send.c
- testsuites/validation/tc-task-construct-errors.c - testsuites/validation/tc-task-construct-errors.c
- testsuites/validation/tc-task-create-errors.c
- testsuites/validation/ts-validation-0.c - testsuites/validation/ts-validation-0.c
stlib: [] stlib: []
target: testsuites/validation/ts-validation-0.exe target: testsuites/validation/ts-validation-0.exe

File diff suppressed because it is too large Load Diff