Commit 334f9db
committed
Zend: handle IS_UNDEF in the generic conversion helpers that still lack it
IS_UNDEF is a legitimate runtime tag that internal code can obtain from an
object property table, and the generic conversion helpers in zend_operators.c
are ZEND_API entry points taking an arbitrary zval. Some already account for
that and some do not:
handled: zendi_try_get_long(), zval_get_long_func(),
__zval_get_string_func(), _convert_to_string()
missing: _zendi_try_convert_scalar_to_number(), convert_to_long(),
convert_to_double(), convert_to_boolean(), zval_get_double_func()
The asymmetry is what is left after two point fixes. 2b38384 taught
zval_try_get_long() about IS_REFERENCE and 9e1b285 (GH-22142) taught
zendi_try_get_long() about IS_UNDEF, each by adding the tag to the one
function that had been reported. The siblings were not revisited, so
zval_get_long(undef) returns 0 while zval_get_double(undef) reaches
ZEND_UNREACHABLE(): an assertion failure in a debug build, undefined
behaviour in a release build.
Add the missing cases to arms that already express the intended result, so
IS_UNDEF behaves as IS_NULL does for the cast helpers and produces a normal
TypeError for the operator helper, matching the bitwise operators which are
already safe through zendi_try_get_long().
increment_function() and decrement_function() are deliberately not changed.
IS_UNDEF must not reach them: every VM handler normalizes it to IS_NULL
before the call (zend_vm_def.h), and the JIT asserts the precondition
outright (zend_jit_helpers.c). Accepting it there would weaken a check
another subsystem relies on.
No behaviour changes for any tag that works today, and no catch-all default
is added: IS_CONSTANT_AST, IS_INDIRECT, IS_PTR, IS_ALIAS_PTR and _IS_ERROR
indicate a caller bug and must keep failing loudly.1 parent 47355da commit 334f9db
1 file changed
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
| 358 | + | |
358 | 359 | | |
359 | 360 | | |
360 | 361 | | |
| |||
556 | 557 | | |
557 | 558 | | |
558 | 559 | | |
| 560 | + | |
559 | 561 | | |
560 | 562 | | |
561 | 563 | | |
| |||
617 | 619 | | |
618 | 620 | | |
619 | 621 | | |
| 622 | + | |
620 | 623 | | |
621 | 624 | | |
622 | 625 | | |
| |||
689 | 692 | | |
690 | 693 | | |
691 | 694 | | |
| 695 | + | |
692 | 696 | | |
693 | 697 | | |
694 | 698 | | |
| |||
1024 | 1028 | | |
1025 | 1029 | | |
1026 | 1030 | | |
| 1031 | + | |
1027 | 1032 | | |
1028 | 1033 | | |
1029 | 1034 | | |
| |||
0 commit comments