Skip to content

Commit c9b9c8c

Browse files
committed
always perform a cookie check when using _mi_segment_of
1 parent 2aee53b commit c9b9c8c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/segment-map.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,16 @@ static mi_segment_t* _mi_segment_of(const void* p) {
113113
size_t bitidx;
114114
mi_segmap_part_t* part = mi_segment_map_index_of(segment, false /* dont alloc if not present */, &index, &bitidx);
115115
if (part == NULL) return NULL;
116-
const uintptr_t mask = mi_atomic_load_relaxed(&part->map[index]);
116+
const uintptr_t mask = mi_atomic_load_relaxed(&part->map[index]);
117117
if mi_likely((mask & ((uintptr_t)1 << bitidx)) != 0) {
118-
bool cookie_ok = (_mi_ptr_cookie(segment) == segment->cookie);
119-
mi_assert_internal(cookie_ok); MI_UNUSED(cookie_ok);
120-
return segment; // yes, allocated by us
118+
// yes, allocated by us
119+
const bool cookie_ok = (_mi_ptr_cookie(segment) == segment->cookie);
120+
if mi_likely(cookie_ok) {
121+
return segment; // yes, allocated by us and valid
122+
}
123+
else {
124+
_mi_error_message(EFAULT, "segment map found an invalid segment, possibly corrupted meta-data (address=%p, segment=%p)\n", p, segment);
125+
}
121126
}
122127
return NULL;
123128
}

0 commit comments

Comments
 (0)