Skip to content

Commit

Permalink
gcc UAF warning in test/perf/singlethread -malloc
Browse files Browse the repository at this point in the history
When building test/perf/singlethread to use the system allocator, gcc
(Debian 14.2.0-3) correctly sees that we were using the value of a
pointer after it had been passed to the privileged free(), which is UB.

Flip the check and dealloc, so that we query the set of pointers we're
tracking first, using the pointer while the allocation is still live.
  • Loading branch information
nwf committed Sep 21, 2024
1 parent 1925909 commit 416fd39
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/test/perf/singlethread/singlethread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void test_alloc_dealloc(size_t count, size_t size, bool write)
{
auto it = set.begin();
void* p = *it;
alloc.dealloc(p, size);
set.erase(it);
SNMALLOC_CHECK(set.find(p) == set.end());
alloc.dealloc(p, size);
}

// alloc 1x objects
Expand Down

0 comments on commit 416fd39

Please sign in to comment.