From b0f6ab7ff26c1152ee4894a86f69b183cfabe94f Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 25 Mar 2021 14:49:52 +0100 Subject: libfstree: add an assertion that root is not NULL If the path argument is "", we assume that referes to root and set the *existing* target node to the root node and skip ahead across the tree search. This leaves "name" uninitialized, which makes coverity panic, because fs->root could be NULL, going down the wrong path. Obviously, this should never, *ever* happen and there is no reasonable recovery strategy if it suddenly does, so simply add an assertion. Signed-off-by: David Oberhollenzer --- lib/fstree/add_by_path.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/fstree/add_by_path.c b/lib/fstree/add_by_path.c index 8918efc..0afd898 100644 --- a/lib/fstree/add_by_path.c +++ b/lib/fstree/add_by_path.c @@ -9,6 +9,7 @@ #include "fstree.h" #include +#include #include tree_node_t *fstree_add_generic(fstree_t *fs, const char *path, @@ -19,6 +20,7 @@ tree_node_t *fstree_add_generic(fstree_t *fs, const char *path, if (*path == '\0') { child = fs->root; + assert(child != NULL); goto out; } -- cgit v1.2.3