summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKinsey Moore <kinsey.moore@oarcorp.com>2020-06-27 19:21:45 -0500
committerJoel Sherrill <joel@rtems.org>2020-08-11 07:51:46 -0500
commit14749c4515d760948c62ffdaee5cc9248cf32933 (patch)
treee7c730c0336ceb2a2cd96ee7bd557c014ac5207c
parent01677dd491a44cc8d2626f69b1208410f9cdcffa (diff)
downloadrtems-14749c4515d760948c62ffdaee5cc9248cf32933.tar.bz2
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
-rw-r--r--cpukit/posix/src/shmunlink.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/cpukit/posix/src/shmunlink.c b/cpukit/posix/src/shmunlink.c
index 053b9c4946..a889b4029c 100644
--- a/cpukit/posix/src/shmunlink.c
+++ b/cpukit/posix/src/shmunlink.c
@@ -29,28 +29,29 @@ int shm_unlink( const char *name )
_Objects_Allocator_lock();
shm = _POSIX_Shm_Get_by_name( name, 0, &obj_err );
- switch ( obj_err ) {
- case OBJECTS_GET_BY_NAME_INVALID_NAME:
- err = ENOENT;
- break;
-
- case OBJECTS_GET_BY_NAME_NAME_TOO_LONG:
- err = ENAMETOOLONG;
- break;
-
- case OBJECTS_GET_BY_NAME_NO_OBJECT:
- default:
- _Objects_Namespace_remove_string(
- &_POSIX_Shm_Information,
- &shm->Object
- );
-
- if ( shm->reference_count == 0 ) {
- /* Only remove the shm object if no references exist to it. Otherwise,
- * the shm object will be freed later in _POSIX_Shm_Attempt_delete */
- _POSIX_Shm_Free( shm );
- }
- break;
+ if ( shm ) {
+ _Objects_Namespace_remove_string(
+ &_POSIX_Shm_Information,
+ &shm->Object
+ );
+
+ if ( shm->reference_count == 0 ) {
+ /* Only remove the shm object if no references exist to it. Otherwise,
+ * the shm object will be freed later in _POSIX_Shm_Attempt_delete */
+ _POSIX_Shm_Free( shm );
+ }
+ } else {
+ switch ( obj_err ) {
+ case OBJECTS_GET_BY_NAME_NAME_TOO_LONG:
+ err = ENAMETOOLONG;
+ break;
+
+ case OBJECTS_GET_BY_NAME_INVALID_NAME:
+ case OBJECTS_GET_BY_NAME_NO_OBJECT:
+ default:
+ err = ENOENT;
+ break;
+ }
}
_Objects_Allocator_unlock();