Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 3ce3dd8 ("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 <deller@gmx.de>
Fixes: 3ce3dd8 ("util/selfmap: Rewrite using qemu/interval-tree.h")
Message-Id: <ZNOsq6Z7t/eyIG/9@p100>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
hdeller authored and rth7680 committed Aug 9, 2023
1 parent 1b65895 commit 47d1e98
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion util/interval-tree.c
Expand Up @@ -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;
}

Expand Down

0 comments on commit 47d1e98

Please sign in to comment.