Skip to content

Commit

Permalink
libsel4vm: Avoid overflowing arithmetic
Browse files Browse the repository at this point in the history
Signed-off-by: Hannu Lyytinen <[email protected]>
  • Loading branch information
hlyytine committed May 26, 2023
1 parent 0aaf0e9 commit 7aa142b
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions libsel4vm/src/guest_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,18 @@ struct frames_map_iterator_cookie {

static inline int reservation_node_cmp(res_tree *x, res_tree *y)
{
if (x->addr < y->addr) {
if (x->addr + x->size > y->addr) {
/* The two regions intersect */
return 0;
} else {
return -1;
}
if (x->addr < y->addr && y->addr - x->addr >= x->size) {
/* x is before y */
return -1;
}
if (x->addr < y->addr + y->size) {
/* The two regions intersect */
return 0;

if (x->addr > y->addr && x->addr - y->addr >= y->size) {
/* y is before x */
return 1;
}
return 1;

/* regions intersect */
return 0;
}

SGLIB_DEFINE_RBTREE_PROTOTYPES(res_tree, left, right, color_field, reservation_node_cmp);
Expand Down

0 comments on commit 7aa142b

Please sign in to comment.