[OpenWrt-Devel] [PATCH libubox 9/9] avl: guard against theoretical null pointer dereference

Petr Štetiar ynezz at true.cz
Wed Nov 20 06:59:26 EST 2019


clang-10 analyzer reports following:

 avl.c:671:25: warning: Access to field 'parent' results in a dereference of a null pointer (loaded from field 'right')
     node->right->parent = parent;
           ~~~~~         ^

Which seems to be impossible to trigger via exported AVL public API, but
it could be probably trigerred by fiddling with the AVL tree node struct
members manually as they are exposed.

Signed-off-by: Petr Štetiar <ynezz at true.cz>
---
 avl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/avl.c b/avl.c
index 8d0bf65aaa5b..e5584051ab94 100644
--- a/avl.c
+++ b/avl.c
@@ -668,7 +668,8 @@ avl_delete_worker(struct avl_tree *tree, struct avl_node *node)
       return;
     }
 
-    node->right->parent = parent;
+    if (node->right)
+      node->right->parent = parent;
 
     if (parent->left == node)
       parent->left = node->right;

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list