From 59d5056a65062ff2b46bcf477651e71f5d4984e0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 13 Aug 2020 17:25:55 +0200 Subject: Fix potential null pointer dereferences --- .clang-tidy | 1 - wscript | 1 - zix/btree.c | 6 ++++-- zix/trie.c | 11 ++++++++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 17b9b27..84771ad 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -9,7 +9,6 @@ Checks: > -cert-err34-c, -cert-msc30-c, -cert-msc50-cpp, - -clang-analyzer-core.NullDereference, -cppcoreguidelines-init-variables, -google-readability-casting, -hicpp-multiway-paths-covered, diff --git a/wscript b/wscript index a69ffb8..858bd51 100644 --- a/wscript +++ b/wscript @@ -59,7 +59,6 @@ def configure(conf): '-Wno-cast-align', '-Wno-conversion', '-Wno-inline', - '-Wno-null-dereference', '-Wno-padded', '-Wno-suggest-attribute=const', '-Wno-suggest-attribute=pure', diff --git a/zix/btree.c b/zix/btree.c index dc8f32b..55d6613 100644 --- a/zix/btree.c +++ b/zix/btree.c @@ -593,8 +593,10 @@ zix_btree_remove(ZixBTree* const t, n->children[1]->n_vals}; n = zix_btree_merge(t, n, 0); - ti->stack[ti->level].node = n; - ti->stack[ti->level].index = counts[i]; + if (ti) { + ti->stack[ti->level].node = n; + ti->stack[ti->level].index = counts[i]; + } } else { // Both child's siblings are minimal, merge them if (i < n->n_vals) { diff --git a/zix/trie.c b/zix/trie.c index 5083f3b..29f31d1 100644 --- a/zix/trie.c +++ b/zix/trie.c @@ -215,7 +215,11 @@ trie_insert_tail(ZixTrieNode** n_ptr, while (first[0]) { assert(zix_trie_node_check(*n_ptr)); - c = realloc_node(NULL, 1); + c = realloc_node(NULL, 1); + if (!c) { + return NULL; + } + c->str = NULL; c->num_children = 0; @@ -225,6 +229,11 @@ trie_insert_tail(ZixTrieNode** n_ptr, ++first; } + + if (!c) { + return NULL; + } + c->num_children = 0; c->str = str; assert(zix_trie_node_check(c)); -- cgit v1.2.1