Changeset 14749c45 in rtems


Ignore:
Timestamp:
Jun 28, 2020, 12:21:45 AM (3 months ago)
Author:
Kinsey Moore <kinsey.moore@…>
Branches:
master
Children:
3ec5f20
Parents:
01677dd
git-author:
Kinsey Moore <kinsey.moore@…> (06/28/20 00:21:45)
git-committer:
Joel Sherrill <joel@…> (08/11/20 12:51:46)
Message:

posix: Only check shm_unlink obj_err if necessary

In the nominal case checked by spsysinit01, obj_err is unmodified if
_POSIX_Shm_Get_by_name returns non-NULL. In the case of shm_unlink, this means
an uninitialized value is passed into the switch and it appears tests using it
were passing by virtue of the stack having the right value on it in most cases.
This now checks obj_err only if _POSIX_Shm_Get_by_name returns NULL.

Close #4016

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/src/shmunlink.c

    r01677dd r14749c45  
    3030
    3131  shm = _POSIX_Shm_Get_by_name( name, 0, &obj_err );
    32   switch ( obj_err ) {
    33     case OBJECTS_GET_BY_NAME_INVALID_NAME:
    34       err = ENOENT;
    35       break;
     32  if ( shm ) {
     33    _Objects_Namespace_remove_string(
     34      &_POSIX_Shm_Information,
     35      &shm->Object
     36    );
    3637
    37     case OBJECTS_GET_BY_NAME_NAME_TOO_LONG:
    38       err = ENAMETOOLONG;
    39       break;
     38    if ( shm->reference_count == 0 ) {
     39      /* Only remove the shm object if no references exist to it. Otherwise,
     40       * the shm object will be freed later in _POSIX_Shm_Attempt_delete */
     41      _POSIX_Shm_Free( shm );
     42    }
     43  } else {
     44    switch ( obj_err ) {
     45      case OBJECTS_GET_BY_NAME_NAME_TOO_LONG:
     46        err = ENAMETOOLONG;
     47        break;
    4048
    41     case OBJECTS_GET_BY_NAME_NO_OBJECT:
    42     default:
    43       _Objects_Namespace_remove_string(
    44         &_POSIX_Shm_Information,
    45         &shm->Object
    46       );
    47 
    48       if ( shm->reference_count == 0 ) {
    49         /* Only remove the shm object if no references exist to it. Otherwise,
    50          * the shm object will be freed later in _POSIX_Shm_Attempt_delete */
    51         _POSIX_Shm_Free( shm );
    52       }
    53       break;
     49      case OBJECTS_GET_BY_NAME_INVALID_NAME:
     50      case OBJECTS_GET_BY_NAME_NO_OBJECT:
     51      default:
     52        err = ENOENT;
     53        break;
     54    }
    5455  }
    5556
Note: See TracChangeset for help on using the changeset viewer.