From 47d1e982318a0d97c557ce349ea9e2b601554055 Mon Sep 17 00:00:00 2001 From: Helge Deller Date: Wed, 9 Aug 2023 17:11:39 +0200 Subject: [PATCH] util/interval-tree: Check root for null in interval_tree_iter_first Fix a crash in qemu-user when running cat /proc/self/maps in a chroot, where /proc isn't mounted. The problem was introduced by commit 3ce3dd8ca965 ("util/selfmap: Rewrite using qemu/interval-tree.h") where in open_self_maps_1() the function read_self_maps() is called and which returns NULL if it can't read the hosts /proc/self/maps file. Afterwards that NULL is fed into interval_tree_iter_first() which doesn't check if the root node is NULL. Fix it by adding a check if root is NULL and return NULL in that case. Signed-off-by: Helge Deller Fixes: 3ce3dd8ca965 ("util/selfmap: Rewrite using qemu/interval-tree.h") Message-Id: Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- util/interval-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/interval-tree.c b/util/interval-tree.c index f2866aa7d3..53465182e6 100644 --- a/util/interval-tree.c +++ b/util/interval-tree.c @@ -797,7 +797,7 @@ IntervalTreeNode *interval_tree_iter_first(IntervalTreeRoot *root, { IntervalTreeNode *node, *leftmost; - if (!root->rb_root.rb_node) { + if (!root || !root->rb_root.rb_node) { return NULL; }