@@ -1644,7 +1644,6 @@ static zend_always_inline void *zend_mm_alloc_heap(zend_mm_heap *heap, size_t si
1644
1644
dbg -> orig_lineno = __zend_orig_lineno ;
1645
1645
ZEND_MM_POISON_DEBUGINFO (dbg );
1646
1646
#endif
1647
- ZEND_MM_UNPOISON (ptr , size );
1648
1647
return ptr ;
1649
1648
} else if (EXPECTED (size <= ZEND_MM_MAX_LARGE_SIZE )) {
1650
1649
ptr = zend_mm_alloc_large (heap , size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
@@ -1658,15 +1657,12 @@ static zend_always_inline void *zend_mm_alloc_heap(zend_mm_heap *heap, size_t si
1658
1657
dbg -> orig_lineno = __zend_orig_lineno ;
1659
1658
ZEND_MM_POISON_DEBUGINFO (dbg );
1660
1659
#endif
1661
- ZEND_MM_UNPOISON (ptr , size );
1662
1660
return ptr ;
1663
1661
} else {
1664
1662
#if ZEND_DEBUG
1665
1663
size = real_size ;
1666
1664
#endif
1667
- ptr = zend_mm_alloc_huge (heap , size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
1668
- ZEND_MM_UNPOISON (ptr , size );
1669
- return ptr ;
1665
+ return zend_mm_alloc_huge (heap , size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
1670
1666
}
1671
1667
}
1672
1668
@@ -1739,6 +1735,7 @@ static zend_never_inline void *zend_mm_realloc_slow(zend_mm_heap *heap, void *pt
1739
1735
size_t orig_peak = heap -> peak ;
1740
1736
#endif
1741
1737
ret = zend_mm_alloc_heap (heap , size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
1738
+ ZEND_MM_UNPOISON (ret , size );
1742
1739
ZEND_MM_UNPOISON (ptr , copy_size );
1743
1740
memcpy (ret , ptr , copy_size );
1744
1741
zend_mm_free_heap (heap , ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
@@ -2826,6 +2823,9 @@ ZEND_API void* ZEND_FASTCALL _zend_mm_alloc(zend_mm_heap *heap, size_t size ZEND
2826
2823
{
2827
2824
ZEND_MM_UNPOISON_HEAP (heap );
2828
2825
void * ptr = zend_mm_alloc_heap (heap , size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
2826
+ if (EXPECTED (ptr )) {
2827
+ ZEND_MM_UNPOISON (ret , size );
2828
+ }
2829
2829
ZEND_MM_POISON_HEAP (heap );
2830
2830
return ptr ;
2831
2831
}
@@ -3106,6 +3106,9 @@ ZEND_API void* ZEND_FASTCALL _emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LI
3106
3106
}
3107
3107
#endif
3108
3108
void * ptr = zend_mm_alloc_heap (AG (mm_heap ), size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
3109
+ if (EXPECTED (ptr )) {
3110
+ ZEND_MM_UNPOISON (ret , size );
3111
+ }
3109
3112
ZEND_MM_POISON_HEAP (AG (mm_heap ));
3110
3113
return ptr ;
3111
3114
}
@@ -3406,7 +3409,7 @@ static void tracked_free(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) {
3406
3409
3407
3410
static void * tracked_realloc (void * ptr , size_t new_size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC ) {
3408
3411
zend_mm_heap * heap = AG (mm_heap );
3409
- ZEND_MM_POISON_HEAP (heap );
3412
+ ZEND_MM_UNPOISON_HEAP (heap );
3410
3413
zval * old_size_zv = NULL ;
3411
3414
size_t old_size = 0 ;
3412
3415
if (ptr ) {
@@ -3428,7 +3431,7 @@ static void *tracked_realloc(void *ptr, size_t new_size ZEND_FILE_LINE_DC ZEND_F
3428
3431
#if ZEND_MM_STAT
3429
3432
heap -> size += new_size - old_size ;
3430
3433
#endif
3431
- ZEND_MM_UNPOISON_HEAP (heap );
3434
+ ZEND_MM_POISON_HEAP (heap );
3432
3435
return ptr ;
3433
3436
}
3434
3437
@@ -3448,16 +3451,19 @@ static void* poison_malloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
3448
3451
if (SIZE_MAX - heap -> debug .padding * 2 < size ) {
3449
3452
zend_mm_panic ("Integer overflow in memory allocation" );
3450
3453
}
3451
- size += heap -> debug .padding * 2 ;
3454
+ size_t sizePlusPadding = size + heap -> debug .padding * 2 ;
3452
3455
3453
- void * ptr = zend_mm_alloc_heap (heap , size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
3456
+ void * ptr = zend_mm_alloc_heap (heap , sizePlusPadding ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
3454
3457
3455
3458
if (EXPECTED (ptr )) {
3456
3459
if (heap -> debug .poison_alloc ) {
3457
- memset (ptr , heap -> debug .poison_alloc_value , size );
3460
+ ZEND_MM_UNPOISON (ptr , sizePlusPadding );
3461
+ memset (ptr , heap -> debug .poison_alloc_value , sizePlusPadding );
3462
+ ZEND_MM_POISON (ptr , sizePlusPadding );
3458
3463
}
3459
3464
3460
3465
ptr = (char * )ptr + heap -> debug .padding ;
3466
+ ZEND_MM_UNPOISON (ptr , size );
3461
3467
}
3462
3468
3463
3469
return ptr ;
@@ -3479,7 +3485,9 @@ static void poison_free(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
3479
3485
size_t size = zend_mm_size (heap , ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
3480
3486
3481
3487
if (heap -> debug .poison_free ) {
3488
+ ZEND_MM_UNPOISON (ptr , heap -> debug .poison_free_value );
3482
3489
memset (ptr , heap -> debug .poison_free_value , size );
3490
+ ZEND_MM_POISON (ptr , heap -> debug .poison_free_value );
3483
3491
}
3484
3492
}
3485
3493
0 commit comments