From 653dbdcdbf3cd4177f5d850f38982adb37d6aff2 Mon Sep 17 00:00:00 2001 From: alessandronardin Date: Thu, 26 Sep 2024 12:17:36 +0200 Subject: [PATCH] posix/aio_misc.c: Added returns on error path in rtems_aio_init() Coverity CID 1619695 Added returns on error path in rtems_aio_init(). Without them the code could access uninitialized memory. Closes #5132. --- cpukit/include/rtems/posix/aio_misc.h | 1 + cpukit/posix/src/aio_misc.c | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cpukit/include/rtems/posix/aio_misc.h b/cpukit/include/rtems/posix/aio_misc.h index 0769e4ff67..f8447ab3f2 100644 --- a/cpukit/include/rtems/posix/aio_misc.h +++ b/cpukit/include/rtems/posix/aio_misc.h @@ -224,6 +224,7 @@ extern rtems_aio_queue aio_request_queue; * @brief Initialize the request queue for AIO Operations. * * @retval 0 The queue has bees succesfully initialized. + * @retval -1 An error occured while initializing the queue. */ int rtems_aio_init( void ); diff --git a/cpukit/posix/src/aio_misc.c b/cpukit/posix/src/aio_misc.c index cf84db2b73..d5729ba32b 100644 --- a/cpukit/posix/src/aio_misc.c +++ b/cpukit/posix/src/aio_misc.c @@ -118,20 +118,24 @@ int rtems_aio_init( void ) int result = 0; result = pthread_attr_init( &aio_request_queue.attr ); - if ( result != 0 ) - return result; + if ( result != 0 ){ + return -1; + } result = pthread_attr_setdetachstate( &aio_request_queue.attr, PTHREAD_CREATE_DETACHED ); - if ( result != 0 ) + if ( result != 0 ) { pthread_attr_destroy( &aio_request_queue.attr ); - + return -1; + } result = pthread_mutex_init( &aio_request_queue.mutex, NULL ); - if ( result != 0 ) + if ( result != 0 ) { pthread_attr_destroy( &aio_request_queue.attr ); + return -1; + } pthread_mutex_lock( &aio_request_queue.mutex ); @@ -140,6 +144,7 @@ int rtems_aio_init( void ) pthread_mutex_unlock( &aio_request_queue.mutex ); pthread_mutex_destroy( &aio_request_queue.mutex ); pthread_attr_destroy( &aio_request_queue.attr ); + return -1; } rtems_chain_initialize_empty( &aio_request_queue.work_req ); @@ -152,7 +157,7 @@ int rtems_aio_init( void ) pthread_mutex_unlock( &aio_request_queue.mutex ); - return result; + return 0; } rtems_aio_request *init_write_req( struct aiocb* aiocbp )