xmemcpy in stack_double is using the size
of the newly doubled stack as the third
parameter. This could result in reading
past the current allocated memory in
"base_alloc" and read invalid memory.
unsigned int n;
int used;
size_t size;
+ size_t new_size;
char* alloc_base;
char* new_alloc_base;
OnigStackType *stk_base, *stk_end, *stk;
stk = *arg_stk;
n = stk_end - stk_base;
- n *= 2;
size = sizeof(OnigStackIndex) * msa->ptr_num + sizeof(OnigStackType) * n;
+ new_size = sizeof(OnigStackIndex) * msa->ptr_num + sizeof(OnigStackType) * n * 2;
if (is_alloca != 0) {
- new_alloc_base = (char* )xmalloc(size);
+ new_alloc_base = (char* )xmalloc(new_size);
if (IS_NULL(new_alloc_base)) {
STACK_SAVE;
return ONIGERR_MEMORY;
else
n = MatchStackLimitSize;
}
- new_alloc_base = (char* )xrealloc(alloc_base, size);
+ new_alloc_base = (char* )xrealloc(alloc_base, new_size);
if (IS_NULL(new_alloc_base)) {
STACK_SAVE;
return ONIGERR_MEMORY;