Skip to content

Commit dfbb425

Browse files
committed
Use safe_*erealloc* flavor in few places to mitigate possible overflows.
1 parent 0ad8b64 commit dfbb425

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

NEWS

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.0alpha3
44

5+
- Core:
6+
. Uses safe_perealloc instead of perealloc for the
7+
ZEND_PTR_STACK_RESIZE_IF_NEEDED to avoid possible overflows. (David Carlier)
8+
59
- DBA:
610
. Fixed LMDB driver hanging when attempting to delete a non-existing key
711
(Girgias)
@@ -14,8 +18,14 @@ PHP NEWS
1418
- Sockets:
1519
. Added TCP_CONGESTION socket option. (David Carlier)
1620

21+
- SPL:
22+
. Uses safe_erealloc instead of erealloc to handle heap growth
23+
for the SplHeap::insert method to avoid possible overflows. (David Carlier)
24+
1725
- Standard:
1826
. Fixed the crypt_sha256/512 api build with clang > 12. (David Carlier)
27+
. Uses safe_erealloc instead of erealloc to handle options in getopt
28+
to avoid possible overflows. (David Carlier)
1929

2030
- Zip:
2131

Zend/zend_ptr_stack.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ END_EXTERN_C()
4848
do { \
4949
stack->max += PTR_STACK_BLOCK_SIZE; \
5050
} while (stack->top+count > stack->max); \
51-
stack->elements = (void **) perealloc(stack->elements, (sizeof(void *) * (stack->max)), stack->persistent); \
51+
stack->elements = (void **) safe_perealloc(stack->elements, sizeof(void *), (stack->max), 0, stack->persistent); \
5252
stack->top_element = stack->elements+stack->top; \
5353
}
5454

ext/spl/spl_heap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static void spl_ptr_heap_insert(spl_ptr_heap *heap, void *elem, void *cmp_userda
278278
if (heap->count+1 > heap->max_size) {
279279
size_t alloc_size = heap->max_size * heap->elem_size;
280280
/* we need to allocate more memory */
281-
heap->elements = erealloc(heap->elements, 2 * alloc_size);
281+
heap->elements = safe_erealloc(heap->elements, 2, alloc_size, 0);
282282
memset((char *) heap->elements + alloc_size, 0, alloc_size);
283283
heap->max_size *= 2;
284284
}

ext/standard/basic_functions.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ PHP_FUNCTION(getopt)
10991099

11001100
/* the first <len> slots are filled by the one short ops
11011101
* we now extend our array and jump to the new added structs */
1102-
opts = (opt_struct *) erealloc(opts, sizeof(opt_struct) * (len + count + 1));
1102+
opts = (opt_struct *) safe_erealloc(opts, sizeof(opt_struct), (len + count + 1), 0);
11031103
orig_opts = opts;
11041104
opts += len;
11051105

0 commit comments

Comments
 (0)