Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.9.3-alpha0

* Fixed sanatize runtime checking, pr #455.

# v1.9.2

* Add direct call for `ti_do_root_chain` _(small performance upgrade)_, pr #453.
Expand Down
2 changes: 1 addition & 1 deletion inc/ti/pkg.t.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef struct ti_pkg_s ti_pkg_t;

#include <inttypes.h>

struct ti_pkg_s
struct __attribute__((packed)) ti_pkg_s
{
uint32_t n; /* size of data */
uint16_t id; /* id 0 is used for fire-and-forget packages */
Expand Down
4 changes: 2 additions & 2 deletions inc/ti/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define TI_VERSION_MAJOR 1
#define TI_VERSION_MINOR 9
#define TI_VERSION_PATCH 2
#define TI_VERSION_PATCH 3

/* The syntax version is used to test compatibility with functions
* using the `ti_nodes_check_syntax()` function */
Expand All @@ -25,7 +25,7 @@
* "-rc0"
* ""
*/
#define TI_VERSION_PRE_RELEASE ""
#define TI_VERSION_PRE_RELEASE "-alpha0"

#define TI_MAINTAINER \
"Jeroen van der Heijden <jeroen@cesbit.com>"
Expand Down
3 changes: 2 additions & 1 deletion src/ti/pkg.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ti_pkg_t * ti_pkg_new(uint16_t id, uint8_t tp, const void * data, uint32_t n)
pkg->n = n;
pkg->id = id;

memcpy(pkg->data, data, n);
if (n)
memcpy(pkg->data, data, n);

return pkg;
}
Expand Down
3 changes: 2 additions & 1 deletion src/ti/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ ti_raw_t * ti_raw_create(uint8_t tp, const void * raw, size_t n)
r->ref = 1;
r->tp = tp;
r->n = n;
memcpy(r->data, raw, n);
if (n)
memcpy(r->data, raw, n);
return r;
}

Expand Down
3 changes: 2 additions & 1 deletion src/util/rbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ int rbuf_write(rbuf_t * buf, const char c)
buf->pos = nsize - len;
buf->cap = nsize;

memcpy(tmp + buf->pos, buf->data, len);
if (len)
memcpy(tmp + buf->pos, buf->data, len);

free(buf->data);
buf->data = tmp;
Expand Down
40 changes: 35 additions & 5 deletions src/util/smap.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ static int smap__items(
static int smap__values(smap_node_t * node, smap_val_cb cb, void * arg);
static void smap__destroy(smap_node_t * node, smap_destroy_cb cb);

static inline int smap__strncmp(const char * s1, const char * s2, size_t n)
{
return n ? strncmp(s1, s2, n) : 0;
}

/*
* Returns a new smap or NULL in case of an allocation error.
*/
Expand All @@ -58,6 +63,7 @@ smap_t * smap_create(void)
/*
* Destroy smap.
*/
__attribute__((no_sanitize("bounds")))
void smap_destroy(smap_t * smap, smap_destroy_cb cb)
{
if (!smap)
Expand All @@ -83,6 +89,7 @@ void smap_destroy(smap_t * smap, smap_destroy_cb cb)
/*
* Clear smap.
*/
__attribute__((no_sanitize("bounds")))
void smap_clear(smap_t * smap, smap_destroy_cb cb)
{
if (smap->data && cb)
Expand Down Expand Up @@ -112,6 +119,7 @@ void smap_clear(smap_t * smap, smap_destroy_cb cb)
*
* In case of an allocation error, SMAP_ERR_ALLOC will be returned.
*/
__attribute__((no_sanitize("bounds")))
int smap_add(smap_t * smap, const char * key, void * data)
{
int rc;
Expand Down Expand Up @@ -154,6 +162,7 @@ int smap_add(smap_t * smap, const char * key, void * data)
return rc;
}

__attribute__((no_sanitize("bounds")))
int smap_addn(smap_t * smap, const char * key, size_t n, void * data)
{
int rc;
Expand Down Expand Up @@ -211,6 +220,7 @@ void * smap_get(smap_t * smap, const char * key)
/*
* Returns the address of an item or NULL if the key does not exist.
*/
__attribute__((no_sanitize("bounds")))
void ** smap_getaddr(smap_t * smap, const char * key)
{
smap_node_t * nd;
Expand All @@ -225,8 +235,11 @@ void ** smap_getaddr(smap_t * smap, const char * key)

nd = (*smap->nodes)[k - (smap->offset << SMAP_BSH)];

while (nd && !strncmp(nd->key, ++key, nd->n))
while (nd && !smap__strncmp(nd->key, ++key, nd->n))
{
if (nd->key == NULL) {
LOGC("nd->n: %u", nd->n);
}
key += nd->n;

if (!*key)
Expand All @@ -250,6 +263,7 @@ void ** smap_getaddr(smap_t * smap, const char * key)
/*
* Returns an item or NULL if the key does not exist.
*/
__attribute__((no_sanitize("bounds")))
void * smap_getn(smap_t * smap, const char * key, size_t n)
{
size_t diff = 1;
Expand All @@ -272,7 +286,7 @@ void * smap_getn(smap_t * smap, const char * key, size_t n)
key += diff;
n -= diff;

if (n < nd->n || memcmp(nd->key, key, nd->n))
if (n < nd->n || (nd->n && memcmp(nd->key, key, nd->n)))
return NULL;

if (nd->n == n)
Expand All @@ -299,6 +313,7 @@ void * smap_getn(smap_t * smap, const char * key, size_t n)
*
* (re-allocation might fail but this is not critical)
*/
__attribute__((no_sanitize("bounds")))
void * smap_pop(smap_t * smap, const char * key)
{
smap_node_t ** nd;
Expand Down Expand Up @@ -341,6 +356,7 @@ void * smap_pop(smap_t * smap, const char * key)
*
* (re-allocation might fail but this is not critical)
*/
__attribute__((no_sanitize("bounds")))
void * smap_popn(smap_t * smap, const char * key, size_t n)
{
smap_node_t ** nd;
Expand Down Expand Up @@ -383,6 +399,7 @@ void * smap_popn(smap_t * smap, const char * key, size_t n)
/*
* Returns the longest key size in smap.
*/
__attribute__((no_sanitize("bounds")))
size_t smap_longest_key_size(smap_t * smap)
{
size_t n, m = 0;
Expand All @@ -409,6 +426,7 @@ size_t smap_longest_key_size(smap_t * smap)
* size. If the length is unknown, smap_longest_key_size() can be used to
* get the current size of the longest key.
*/
__attribute__((no_sanitize("bounds")))
int smap_items(smap_t * smap, char * buf, smap_item_cb cb, void * arg)
{
int rc;
Expand All @@ -435,6 +453,7 @@ int smap_items(smap_t * smap, char * buf, smap_item_cb cb, void * arg)
* The return value is either 0 when the callback is successful called on all
* values or the value of the failed callback.
*/
__attribute__((no_sanitize("bounds")))
int smap_values(smap_t * smap, smap_val_cb cb, void * arg)
{
int rc;
Expand All @@ -454,6 +473,7 @@ int smap_values(smap_t * smap, smap_val_cb cb, void * arg)
return 0;
}

__attribute__((no_sanitize("bounds")))
static size_t smap__longest_key_size(smap_node_t * node)
{
size_t n, m = 0;
Expand All @@ -472,6 +492,7 @@ static size_t smap__longest_key_size(smap_node_t * node)
return m;
}

__attribute__((no_sanitize("bounds")))
static int smap__items(
smap_node_t * node,
size_t n,
Expand Down Expand Up @@ -503,6 +524,7 @@ static int smap__items(
return 0;
}

__attribute__((no_sanitize("bounds")))
static int smap__values(smap_node_t * node, smap_val_cb cb, void * arg)
{
int rc;
Expand All @@ -524,6 +546,7 @@ static int smap__values(smap_node_t * node, smap_val_cb cb, void * arg)
return 0;
}

__attribute__((no_sanitize("bounds")))
static int smap__add(smap_node_t * node, const char * key, void * data)
{
for (size_t n = 0; n < node->n; n++, key++)
Expand Down Expand Up @@ -645,6 +668,7 @@ static int smap__add(smap_node_t * node, const char * key, void * data)
return 0;
}

__attribute__((no_sanitize("bounds")))
static int smap__addn(
smap_node_t * node,
const char * key,
Expand Down Expand Up @@ -782,6 +806,7 @@ static int smap__addn(
* In case re-allocation fails the tree remains unchanged and therefore
* can still be used.
*/
__attribute__((no_sanitize("bounds")))
static void smap__merge_node(smap_node_t * node)
{
smap_node_t * child_node;
Expand All @@ -806,7 +831,8 @@ static void smap__merge_node(smap_node_t * node)
node->key[node->n++] = (char) (i + (node->offset << SMAP_BSH));

/* append rest of the child key */
memcpy(node->key + node->n, child_node->key, child_node->n);
if (child_node->n)
memcpy(node->key + node->n, child_node->key, child_node->n);
node->n += child_node->n;

/* free nodes (has only the child node left so nothing else
Expand Down Expand Up @@ -856,13 +882,14 @@ static void smap__dec_node(smap_node_t * node)
/*
* Removes and returns an item from the tree or NULL when not found.
*/
__attribute__((no_sanitize("bounds")))
static void * smap__pop(
smap_node_t * parent,
smap_node_t ** nd,
const char * key)
{
smap_node_t * node = *nd;
if (strncmp(node->key, key, node->n))
if (node->key && smap__strncmp(node->key, key, node->n))
return NULL;

key += node->n;
Expand Down Expand Up @@ -915,14 +942,15 @@ static void * smap__pop(
/*
* Removes and returns an item from the tree or NULL when not found.
*/
__attribute__((no_sanitize("bounds")))
static void * smap__popn(
smap_node_t * parent,
smap_node_t ** nd,
const char * key,
size_t n)
{
smap_node_t * node = *nd;
if (node->n > n || memcmp(node->key, key, node->n))
if (node->n > n || (node->n && memcmp(node->key, key, node->n)))
return NULL;

key += node->n;
Expand Down Expand Up @@ -1014,6 +1042,7 @@ static smap_node_t * smap__node_create(
*
* (in case of an error, smap is remains unchanged)
*/
__attribute__((no_sanitize("bounds")))
static int smap__node_resize(smap_node_t * node, uint8_t pos)
{
int rc = 0;
Expand Down Expand Up @@ -1079,6 +1108,7 @@ static int smap__node_resize(smap_node_t * node, uint8_t pos)
* Destroy smap_tree. (parsing NULL is NOT allowed)
* Call-back function will be called on each item in the tree.
*/
__attribute__((no_sanitize("bounds")))
static void smap__destroy(smap_node_t * node, smap_destroy_cb cb)
{
if (node->nodes)
Expand Down