Skip to content

Commit eb85c33

Browse files
committed
Check size_t bounds overflow in create_mem_region
1 parent 1b33b54 commit eb85c33

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

riscv/cfg.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ bool mem_cfg_t::check_if_supported(reg_t base, reg_t size)
1818
// the regions in the first place, but we have them here to make sure that
1919
// we can't end up describing memory regions that don't make sense. They
2020
// ask that the page size is a multiple of the minimum page size, that the
21-
// page is aligned to the minimum page size, that the page is non-empty and
22-
// that the top address is still representable in a reg_t.
21+
// page is aligned to the minimum page size, that the page is non-empty,
22+
// that the size doesn't overflow size_t, and that the top address is still
23+
// representable in a reg_t.
2324
//
2425
// Note: (base + size == 0) part of the assertion is to handle cases like
2526
// { base = 0xffff_ffff_ffff_f000, size: 0x1000 }
2627
return (size % PGSIZE == 0) &&
2728
(base % PGSIZE == 0) &&
29+
(size_t(size) == size) &&
2830
(size > 0) &&
2931
((base + size > base) || (base + size == 0));
3032
}

0 commit comments

Comments
 (0)