Skip to content

Commit

Permalink
malloc_usable_size: clean abort on invalid region
Browse files Browse the repository at this point in the history
It's the region pointer that can be NULL here, and p was checked at the
beginning of the function. Also fix the test accordingly.
  • Loading branch information
tsautereau-anssi authored and thestinger committed Feb 10, 2021
1 parent 5c8b686 commit 76860c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion h_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,7 @@ EXPORT size_t h_malloc_usable_size(H_MALLOC_USABLE_SIZE_CONST void *p) {
struct region_allocator *ra = ro.region_allocator;
mutex_lock(&ra->lock);
struct region_metadata *region = regions_find(p);
if (p == NULL) {
if (region == NULL) {
fatal_error("invalid malloc_usable_size");
}
size_t size = region->size;
Expand Down
6 changes: 4 additions & 2 deletions test/simple-memory-corruption/test_smc.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ def test_uninitialized_free(self):
"fatal allocator error: invalid free\n")

def test_uninitialized_malloc_usable_size(self):
_stdout, _stderr, returncode = self.run_test(
_stdout, stderr, returncode = self.run_test(
"uninitialized_malloc_usable_size")
self.assertEqual(returncode, -11)
self.assertEqual(returncode, -6)
self.assertEqual(stderr.decode("utf-8"),
"fatal allocator error: invalid malloc_usable_size\n")

def test_uninitialized_realloc(self):
_stdout, stderr, returncode = self.run_test("uninitialized_realloc")
Expand Down

0 comments on commit 76860c7

Please sign in to comment.