You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2019/02/22 18:05:15 UTC
[mynewt-core] branch master updated: mempool_tests: Fix stack
corruption bug
This is an automated email from the ASF dual-hosted git repository.
ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new d90e364 mempool_tests: Fix stack corruption bug
d90e364 is described below
commit d90e364de2196457c1e8b186b9a9d032f6bb4442
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Feb 21 16:20:20 2019 -0800
mempool_tests: Fix stack corruption bug
The "extended mempool" tests were causing stack corruption. These tests
registered mempools that were allocated on the stack and never
unregistered them. So, after these tests ran, the global mempool list
contained some invalid entries. Subsequently attempting to iterate or
append to the list resulted in a crash or other unpredictable behavior.
The solution is:
1. Statically allocate the mempools.
2. Always unregister the relevant mempool at the start of each test.
This is now the non-extended tests are already implemented.
---
kernel/os/test/src/testcases/os_mempool_test_case.c | 1 +
kernel/os/test/src/testcases/os_mempool_test_ext_basic.c | 5 ++++-
kernel/os/test/src/testcases/os_mempool_test_ext_nested.c | 5 ++++-
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/kernel/os/test/src/testcases/os_mempool_test_case.c b/kernel/os/test/src/testcases/os_mempool_test_case.c
index 044c458..d98432f 100644
--- a/kernel/os/test/src/testcases/os_mempool_test_case.c
+++ b/kernel/os/test/src/testcases/os_mempool_test_case.c
@@ -36,6 +36,7 @@ mempool_test(int num_blocks, int block_size, bool clear)
void *block;
os_error_t rc;
+ /* Attempt to unregister the pool in case this test has already run. */
os_mempool_unregister(&g_TstMempool);
/* Check for too many blocks */
diff --git a/kernel/os/test/src/testcases/os_mempool_test_ext_basic.c b/kernel/os/test/src/testcases/os_mempool_test_ext_basic.c
index 939f6e3..626a86e 100644
--- a/kernel/os/test/src/testcases/os_mempool_test_ext_basic.c
+++ b/kernel/os/test/src/testcases/os_mempool_test_ext_basic.c
@@ -21,6 +21,7 @@
static struct os_mempool_ext *freed_pool;
static void *freed_block;
+static struct os_mempool_ext pool;
static os_error_t
put_cb(struct os_mempool_ext *mpe, void *block, void *arg)
@@ -39,10 +40,12 @@ put_cb(struct os_mempool_ext *mpe, void *block, void *arg)
TEST_CASE(os_mempool_test_ext_basic)
{
uint8_t buf[OS_MEMPOOL_BYTES(10, 32)];
- struct os_mempool_ext pool;
int *ip;
int rc;
+ /* Attempt to unregister the pool in case this test has already run. */
+ os_mempool_unregister(&pool.mpe_mp);
+
rc = os_mempool_ext_init(&pool, 10, 32, buf, "test_ext_basic");
TEST_ASSERT_FATAL(rc == 0);
diff --git a/kernel/os/test/src/testcases/os_mempool_test_ext_nested.c b/kernel/os/test/src/testcases/os_mempool_test_ext_nested.c
index 7dbf4d6..959215a 100644
--- a/kernel/os/test/src/testcases/os_mempool_test_ext_nested.c
+++ b/kernel/os/test/src/testcases/os_mempool_test_ext_nested.c
@@ -19,6 +19,7 @@
#include "os_test_priv.h"
static int num_frees;
+static struct os_mempool_ext pool;
static os_error_t
put_cb(struct os_mempool_ext *mpe, void *block, void *arg)
@@ -45,10 +46,12 @@ put_cb(struct os_mempool_ext *mpe, void *block, void *arg)
TEST_CASE(os_mempool_test_ext_nested)
{
uint8_t buf[OS_MEMPOOL_BYTES(10, 32)];
- struct os_mempool_ext pool;
int *elem;
int rc;
+ /* Attempt to unregister the pool in case this test has already run. */
+ os_mempool_unregister(&pool.mpe_mp);
+
rc = os_mempool_ext_init(&pool, 10, 32, buf, "test_ext_nested");
TEST_ASSERT_FATAL(rc == 0);