Skip to content

Commit 56aebbe

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: SplHeap: Avoid memcpy on overlapping pointer
2 parents 40cdc5f + afe1423 commit 56aebbe

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ext/spl/spl_heap.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ static zend_always_inline void *spl_heap_elem(spl_ptr_heap *heap, size_t i) {
9696
}
9797

9898
static zend_always_inline void spl_heap_elem_copy(spl_ptr_heap *heap, void *to, void *from) {
99+
assert(to != from);
99100
memcpy(to, from, heap->elem_size);
100101
}
101102

@@ -325,7 +326,10 @@ static int spl_ptr_heap_delete_top(spl_ptr_heap *heap, void *elem, void *cmp_use
325326
heap->flags |= SPL_HEAP_CORRUPTED;
326327
}
327328

328-
spl_heap_elem_copy(heap, spl_heap_elem(heap, i), bottom);
329+
void *to = spl_heap_elem(heap, i);
330+
if (to != bottom) {
331+
spl_heap_elem_copy(heap, to, bottom);
332+
}
329333
return SUCCESS;
330334
}
331335
/* }}} */

0 commit comments

Comments
 (0)