Skip to content

Commit b814342

Browse files
committed
handle overflow of arena_base_next
1 parent 257ba98 commit b814342

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Objects/obmalloc.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,15 +2961,18 @@ arena_map_mark_used(uintptr_t arena_base, int is_used)
29612961
* again (do the full tree traversal).
29622962
*/
29632963
n_hi->arenas[i3].tail_hi = is_used ? tail : 0;
2964-
uintptr_t arena_base_next = arena_base + ARENA_SIZE;
2965-
arena_map3_t *n_lo = arena_map_get((block *)arena_base_next, is_used);
2966-
if (n_lo == NULL) {
2967-
assert(is_used); /* otherwise should already exist */
2968-
n_hi->arenas[i3].tail_hi = 0;
2969-
return 0; /* failed to allocate space for node */
2964+
uintptr_t arena_next = arena_base + ARENA_SIZE;
2965+
/* check for overflow of arena_next */
2966+
if (arena_next > arena_base) {
2967+
arena_map3_t *n_lo = arena_map_get((block *)arena_next, is_used);
2968+
if (n_lo == NULL) {
2969+
assert(is_used); /* otherwise should already exist */
2970+
n_hi->arenas[i3].tail_hi = 0;
2971+
return 0; /* failed to allocate space for node */
2972+
}
2973+
int i3_next = MAP3_INDEX(arena_next);
2974+
n_lo->arenas[i3_next].tail_lo = is_used ? tail : 0;
29702975
}
2971-
int i3_next = MAP3_INDEX(arena_base_next);
2972-
n_lo->arenas[i3_next].tail_lo = is_used ? tail : 0;
29732976
}
29742977
return 1;
29752978
}

0 commit comments

Comments
 (0)