From fe939281be68c8f43c2ebf4c4a80e2c9d1ff4781 Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Thu, 2 Jan 2020 19:00:29 +0100 Subject: [PATCH 1/2] Fix #337: fix memory corruption produced by misplaced memset() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling memset too late after assigning the `sem` variable in the code of `OS_BinSemCreate_Impl` caused the data pointed to by `sem` to get corrupted. The issue was not caught by the existing test suite for POSIX OSAL when running on Linux. However running the test suite on macOS revealed the anomalies in the behavior of `pthread_cond_destroy()` which was working on the corrupted memory as was demonstrated in: Calling pthread_cond_destroy results in “Function not implemented” ENOSYS on macOS, https://stackoverflow.com/questions/59560940/calling-pthread-cond-destroy-results-in-function-not-implemented-enosys-on-mac?noredirect=1#comment105301077_59560940 The original commit that introduced the issue is: https://github.com/nasa/osal/commit/bfa7a33020e9a77221352a99bd2dbee4860ba852 --- src/os/posix/osapi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/os/posix/osapi.c b/src/os/posix/osapi.c index c41cda190..b40728d0a 100644 --- a/src/os/posix/osapi.c +++ b/src/os/posix/osapi.c @@ -1465,6 +1465,8 @@ int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 initial_value, uint32 options) mutex_created = 0; cond_created = 0; sem = &OS_impl_bin_sem_table[sem_id]; + memset(sem, 0, sizeof (*sem)); + do { /* @@ -1522,7 +1524,6 @@ int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 initial_value, uint32 options) ** fill out the proper OSAL table fields */ - memset(sem, 0, sizeof (*sem)); sem->current_value = initial_value; return_code = OS_SUCCESS; From 7d1f33d92e4674094b3ca8ff0cc51f012d24d8fb Mon Sep 17 00:00:00 2001 From: "Gerardo E. Cruz-Ortiz" <59618057+astrogeco@users.noreply.github.com> Date: Fri, 28 Feb 2020 16:01:46 -0500 Subject: [PATCH 2/2] Increase version to 5.0.7 and update README --- README.md | 5 +++-- src/os/inc/osapi-version.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f2fad8205..2f87d54eb 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,9 @@ This distribution contains: Version Notes: ============== - +- 5.0.7: DEVELOPMENT + - Fixes memset bug + - Minor updates (see https://github.com/nasa/osal/pull/361) - 5.0.6: DEVELOPMENT - Minor updates (see https://github.com/nasa/osal/pull/355) - 5.0.5: DEVELOPMENT @@ -117,4 +119,3 @@ License information: ==================== This software is licensed under NASAs Open Source Agreement. The release of the software is conditional upon the recipients acceptance of the Open Source Agreement. Please see the file: NASA_Open_Source_Agreement_1_3-OS_AbstractionLayer.txt - diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index 9d5ffbebf..24f8d9a85 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -20,7 +20,7 @@ #define OS_MAJOR_VERSION 5 #define OS_MINOR_VERSION 0 -#define OS_REVISION 6 +#define OS_REVISION 7 #define OS_MISSION_REV 0 /**