Changeset 08cbd4ba in rtems


Ignore:
Timestamp:
Feb 26, 2021, 11:34:21 AM (8 weeks ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
34f279aa
Parents:
9dad735
git-author:
Sebastian Huber <sebastian.huber@…> (02/26/21 11:34:21)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/01/21 06:18:14)
Message:

score: Fix _Stack_Extend_size()

Check for an integer overflow. Add a validation test for task create
errors.

Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/score/stackimpl.h

    r9dad735 r08cbd4ba  
    120120
    121121/**
    122  * @brief Extend the stack size to account for additional data structures
    123  *   allocated in the stack area of a thread.
     122 * @brief Extends the stack size to account for additional data structures
     123 *   allocated in the thread storage area.
    124124 *
    125  * @param stack_size The stack size.
    126  * @param is_fp Indicates if the stack is for a floating-point thread.
     125 * @param stack_size is the stack size.
    127126 *
    128  * @return The extended stack size.
     127 * @param is_fp shall be true, if the stack is for a floating-point thread,
     128 *   otherwise it shall be false.
     129 *
     130 * @return Returns the extended stack size.
    129131 */
    130132RTEMS_INLINE_ROUTINE size_t _Stack_Extend_size(
     
    133135)
    134136{
     137  size_t extra_size;
     138
     139  extra_size = _TLS_Get_allocation_size();
     140
    135141#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
    136142  if ( is_fp ) {
    137     stack_size += CONTEXT_FP_SIZE;
     143    /* This addition cannot overflow since the TLS size cannot be that large */
     144    extra_size += CONTEXT_FP_SIZE;
    138145  }
    139146#else
     
    141148#endif
    142149
    143   stack_size += _TLS_Get_allocation_size();
     150  stack_size += extra_size;
     151
     152  if ( stack_size < extra_size ) {
     153    /*
     154     * In case of an unsigned integer overflow, saturate at the maximum value.
     155     */
     156    stack_size = SIZE_MAX;
     157  }
    144158
    145159  return stack_size;
  • spec/build/testsuites/validation/validation-0.yml

    r9dad735 r08cbd4ba  
    2121- testsuites/validation/tc-signal-send.c
    2222- testsuites/validation/tc-task-construct-errors.c
     23- testsuites/validation/tc-task-create-errors.c
    2324- testsuites/validation/ts-validation-0.c
    2425stlib: []
Note: See TracChangeset for help on using the changeset viewer.