diff options
author | Michael Scott <michael.scott@linaro.org> | 2017-04-27 13:54:45 -0700 |
---|---|---|
committer | Anas Nashif <nashif@linux.intel.com> | 2017-04-28 12:36:40 +0000 |
commit | 841a59cb0c0fe06a59be741e28b7b92d305cfb68 (patch) | |
tree | eda8f8f260cf7c9a2e82a9177771e4149313ce80 | |
parent | acedb70a943036c87d6c0373a74a094abdef5ee3 (diff) |
slist/dlist: container node can't be NULL in *_PEEK_NEXT_CONTAINER
Using MPU enabled HW it was evident that a NULL access
(with offset) was happening in the TCP stack due to the
following message:
***** MPU FAULT *****
Executing thread ID (thread): 0x20009b0c
Faulting instruction address: 0x8034496
Data Access Violation
Address: 0x34
Fatal fault in essential thread! Spinning...
Turns out we are referencing a potentially de-referenced
NULL pointer in the SYS_SLIST_PEEK_NEXT_CONTAINER macro.
Let's avoid this by checking the container node for NULL.
Also fix dlist.h SYS_DLIST_PEEK_NEXT_CONTAINER with the same
issue.
Change-Id: I2e765b9af7bcaf8fb13f7c9b7e081f9e6d4928f2
Signed-off-by: Michael Scott <michael.scott@linaro.org>
-rw-r--r-- | include/misc/dlist.h | 3 | ||||
-rw-r--r-- | include/misc/slist.h | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/include/misc/dlist.h b/include/misc/dlist.h index 2826bf2a8..72275238e 100644 --- a/include/misc/dlist.h +++ b/include/misc/dlist.h @@ -127,7 +127,8 @@ typedef struct _dnode sys_dnode_t; * @param __n The field name of sys_dnode_t within the container struct */ #define SYS_DLIST_PEEK_NEXT_CONTAINER(__dl, __cn, __n) \ - SYS_DLIST_CONTAINER(sys_dlist_peek_next(__dl, &(__cn->__n)), __cn, __n) + ((__cn) ? SYS_DLIST_CONTAINER(sys_dlist_peek_next(__dl, &(__cn->__n)), \ + __cn, __n) : NULL) /** * @brief Provide the primitive to iterate on a list under a container diff --git a/include/misc/slist.h b/include/misc/slist.h index c18d2b8e9..a3da0bfbb 100644 --- a/include/misc/slist.h +++ b/include/misc/slist.h @@ -133,7 +133,8 @@ typedef struct _slist sys_slist_t; */ #define SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n) \ - SYS_SLIST_CONTAINER(sys_slist_peek_next(&((__cn)->__n)), __cn, __n) + ((__cn) ? SYS_SLIST_CONTAINER(sys_slist_peek_next(&((__cn)->__n)), \ + __cn, __n) : NULL) /** * @brief Provide the primitive to iterate on a list under a container |