Commit f761d44
committed
Fix GH-20482: heap use-after-free in ZEND_ASSIGN_DIM via re-entrant user output handler
When ZEND_ASSIGN_DIM evaluates an undefined CV as the RHS, the warning
emitted by zval_undefined_cv() can be routed through a user output
handler (e.g. via ob_start with a small chunk size). The handler is
allowed to run arbitrary PHP code, including reassigning the variable
that holds the array we are writing to. That drops the array's last
reference and zend_array_destroy frees its buckets while the VM still
holds the previously-fetched variable_ptr, causing a UAF on the
subsequent zend_assign_to_variable_ex.
Mirror the protection already used in the IS_UNUSED branch of
ZEND_ASSIGN_DIM (and in slow_index_convert): temporarily addref the
target HashTable around zval_undefined_cv() so the array survives the
reentrant user code, then refetch the dimension address afterwards
(the previous variable_ptr may have been invalidated even when the
array as a whole survived, e.g. if user code added entries that
triggered a rehash).
Includes a phpt regression covering the output-handler reentrancy
path.1 parent 1462499 commit f761d44
4 files changed
Lines changed: 1010 additions & 147 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2730 | 2730 | | |
2731 | 2731 | | |
2732 | 2732 | | |
| 2733 | + | |
2733 | 2734 | | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
2734 | 2752 | | |
2735 | | - | |
| 2753 | + | |
2736 | 2754 | | |
2737 | | - | |
| 2755 | + | |
2738 | 2756 | | |
2739 | 2757 | | |
2740 | 2758 | | |
2741 | 2759 | | |
2742 | | - | |
2743 | 2760 | | |
2744 | 2761 | | |
2745 | 2762 | | |
| |||
0 commit comments