Skip to content

Commit 422aa17

Browse files
committed
Fix GH-15901: phpdbg: Assertion failure on i funcs
New hash tables are not automatically packed, so we must not treat them as such. Therefore we guard the foreach appropriately. Closes GH-15929.
1 parent b26e610 commit 422aa17

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ PHP NEWS
1212
. Fixed regression where signs after the first one were ignored while parsing
1313
a signed integer, with the DateTimeInterface::modify() function. (Derick)
1414

15+
- PHPDBG:
16+
. Fixed bug GH-15901 (phpdbg: Assertion failure on i funcs). (cmb)
17+
1518
- SimpleXML:
1619
. Fixed bug GH-15837 (Segmentation fault in ext/simplexml/simplexml.c).
1720
(nielsdos)

sapi/phpdbg/phpdbg_info.c

+32-28
Original file line numberDiff line numberDiff line change
@@ -399,27 +399,29 @@ PHPDBG_INFO(classes) /* {{{ */
399399
phpdbg_notice("User Classes (%d)", zend_hash_num_elements(&classes));
400400

401401
/* once added, assume that classes are stable... until shutdown. */
402-
ZEND_HASH_PACKED_FOREACH_PTR(&classes, ce) {
403-
phpdbg_print_class_name(ce);
404-
405-
if (ce->parent) {
406-
if (ce->ce_flags & ZEND_ACC_LINKED) {
407-
zend_class_entry *pce = ce->parent;
408-
do {
409-
phpdbg_out("|-------- ");
410-
phpdbg_print_class_name(pce);
411-
} while ((pce = pce->parent));
412-
} else {
413-
phpdbg_writeln("|-------- User Class %s (not yet linked because declaration for parent was not encountered when declaring the class)", ZSTR_VAL(ce->parent_name));
402+
if (HT_IS_INITIALIZED(&classes)) {
403+
ZEND_HASH_PACKED_FOREACH_PTR(&classes, ce) {
404+
phpdbg_print_class_name(ce);
405+
406+
if (ce->parent) {
407+
if (ce->ce_flags & ZEND_ACC_LINKED) {
408+
zend_class_entry *pce = ce->parent;
409+
do {
410+
phpdbg_out("|-------- ");
411+
phpdbg_print_class_name(pce);
412+
} while ((pce = pce->parent));
413+
} else {
414+
phpdbg_writeln("|-------- User Class %s (not yet linked because declaration for parent was not encountered when declaring the class)", ZSTR_VAL(ce->parent_name));
415+
}
414416
}
415-
}
416417

417-
if (ce->info.user.filename) {
418-
phpdbg_writeln("|---- in %s on line %u", ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
419-
} else {
420-
phpdbg_writeln("|---- no source code");
421-
}
422-
} ZEND_HASH_FOREACH_END();
418+
if (ce->info.user.filename) {
419+
phpdbg_writeln("|---- in %s on line %u", ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
420+
} else {
421+
phpdbg_writeln("|---- no source code");
422+
}
423+
} ZEND_HASH_FOREACH_END();
424+
}
423425

424426
zend_hash_destroy(&classes);
425427

@@ -445,17 +447,19 @@ PHPDBG_INFO(funcs) /* {{{ */
445447

446448
phpdbg_notice("User Functions (%d)", zend_hash_num_elements(&functions));
447449

448-
ZEND_HASH_PACKED_FOREACH_PTR(&functions, zf) {
449-
zend_op_array *op_array = &zf->op_array;
450+
if (HT_IS_INITIALIZED(&functions)) {
451+
ZEND_HASH_PACKED_FOREACH_PTR(&functions, zf) {
452+
zend_op_array *op_array = &zf->op_array;
450453

451-
phpdbg_write("|-------- %s", op_array->function_name ? ZSTR_VAL(op_array->function_name) : "{main}");
454+
phpdbg_write("|-------- %s", op_array->function_name ? ZSTR_VAL(op_array->function_name) : "{main}");
452455

453-
if (op_array->filename) {
454-
phpdbg_writeln(" in %s on line %d", ZSTR_VAL(op_array->filename), op_array->line_start);
455-
} else {
456-
phpdbg_writeln(" (no source code)");
457-
}
458-
} ZEND_HASH_FOREACH_END();
456+
if (op_array->filename) {
457+
phpdbg_writeln(" in %s on line %d", ZSTR_VAL(op_array->filename), op_array->line_start);
458+
} else {
459+
phpdbg_writeln(" (no source code)");
460+
}
461+
} ZEND_HASH_FOREACH_END();
462+
}
459463

460464
zend_hash_destroy(&functions);
461465

sapi/phpdbg/tests/gh15901.phpt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
GH-15901 (phpdbg: Assertion failure on `i funcs`)
3+
--PHPDBG--
4+
i funcs
5+
i classes
6+
--EXPECT--
7+
prompt> [User Functions (0)]
8+
prompt> [User Classes (0)]
9+
prompt> [User Classes (0)]
10+
prompt>

0 commit comments

Comments
 (0)