Skip to content

Commit d14498a

Browse files
committed
Ignore non-executable opcodes in line mode of phpdbg_end_oplog()
1 parent b8fab50 commit d14498a

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PHP NEWS
2222
. Properly allow for stdin input from a file. (Bob)
2323
. Add -s command line option / stdin command for reading script from stdin.
2424
(Bob)
25+
. Ignore non-executable opcodes in line mode of phpdbg_end_oplog(). (Bob)
2526

2627
- Session:
2728
. Fixed bug #73273 (session_unset() empties values from all variables in which

sapi/phpdbg/phpdbg.c

+19-9
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,16 @@ static PHP_FUNCTION(phpdbg_start_oplog)
443443
PHPDBG_G(oplog_list)->start = PHPDBG_G(oplog_cur);
444444
}
445445

446+
static zend_always_inline zend_bool phpdbg_is_ignored_opcode(zend_uchar opcode) {
447+
return
448+
opcode == ZEND_NOP || opcode == ZEND_OP_DATA || opcode == ZEND_FE_FREE || opcode == ZEND_FREE || opcode == ZEND_ASSERT_CHECK || opcode == ZEND_VERIFY_RETURN_TYPE
449+
|| opcode == ZEND_DECLARE_CONST || opcode == ZEND_DECLARE_CLASS || opcode == ZEND_DECLARE_INHERITED_CLASS || opcode == ZEND_DECLARE_FUNCTION
450+
|| opcode == ZEND_DECLARE_INHERITED_CLASS_DELAYED || opcode == ZEND_VERIFY_ABSTRACT_CLASS || opcode == ZEND_ADD_TRAIT || opcode == ZEND_BIND_TRAITS
451+
|| opcode == ZEND_DECLARE_ANON_CLASS || opcode == ZEND_DECLARE_ANON_INHERITED_CLASS || opcode == ZEND_FAST_RET || opcode == ZEND_TICKS
452+
|| opcode == ZEND_EXT_STMT || opcode == ZEND_EXT_FCALL_BEGIN || opcode == ZEND_EXT_FCALL_END || opcode == ZEND_EXT_NOP || opcode == ZEND_BIND_GLOBAL
453+
;
454+
}
455+
446456
static void phpdbg_oplog_fill_executable(zend_op_array *op_array, HashTable *insert_ht, zend_bool by_opcode) {
447457
/* ignore RECV_* opcodes */
448458
zend_op *cur = op_array->opcodes + op_array->num_args + !!(op_array->fn_flags & ZEND_ACC_VARIADIC);
@@ -460,11 +470,8 @@ static void phpdbg_oplog_fill_executable(zend_op_array *op_array, HashTable *ins
460470
}
461471

462472
for (; cur < end; cur++) {
463-
if (cur->opcode == ZEND_NOP || cur->opcode == ZEND_OP_DATA || cur->opcode == ZEND_FE_FREE || cur->opcode == ZEND_FREE || cur->opcode == ZEND_ASSERT_CHECK || cur->opcode == ZEND_VERIFY_RETURN_TYPE
464-
|| cur->opcode == ZEND_DECLARE_CONST || cur->opcode == ZEND_DECLARE_CLASS || cur->opcode == ZEND_DECLARE_INHERITED_CLASS || cur->opcode == ZEND_DECLARE_FUNCTION
465-
|| cur->opcode == ZEND_DECLARE_INHERITED_CLASS_DELAYED || cur->opcode == ZEND_VERIFY_ABSTRACT_CLASS || cur->opcode == ZEND_ADD_TRAIT || cur->opcode == ZEND_BIND_TRAITS
466-
|| cur->opcode == ZEND_DECLARE_ANON_CLASS || cur->opcode == ZEND_DECLARE_ANON_INHERITED_CLASS || cur->opcode == ZEND_FAST_RET || cur->opcode == ZEND_TICKS
467-
|| cur->opcode == ZEND_EXT_STMT || cur->opcode == ZEND_EXT_FCALL_BEGIN || cur->opcode == ZEND_EXT_FCALL_END || cur->opcode == ZEND_EXT_NOP || cur->opcode == ZEND_BIND_GLOBAL) {
473+
zend_uchar opcode = cur->opcode;
474+
if (phpdbg_is_ignored_opcode(opcode)) {
468475
continue;
469476
}
470477

@@ -474,7 +481,7 @@ static void phpdbg_oplog_fill_executable(zend_op_array *op_array, HashTable *ins
474481
insert_idx = cur->lineno;
475482
}
476483

477-
if (cur->opcode == ZEND_NEW && (cur + 1)->opcode == ZEND_DO_FCALL) {
484+
if (opcode == ZEND_NEW && cur[1].opcode == ZEND_DO_FCALL) {
478485
cur++;
479486
}
480487

@@ -492,7 +499,7 @@ static inline HashTable* phpdbg_add_empty_array(HashTable *ht, zend_string *name
492499
return Z_ARR_P(ht_zv);
493500
}
494501

495-
/* {{{ proto void phpdbg_end_oplog() */
502+
/* {{{ proto void phpdbg_get_executable() */
496503
static PHP_FUNCTION(phpdbg_get_executable)
497504
{
498505
HashTable *options = NULL;
@@ -669,6 +676,10 @@ static PHP_FUNCTION(phpdbg_end_oplog)
669676
if (by_opcode) {
670677
insert_idx = cur->op - cur->opcodes;
671678
} else {
679+
if (phpdbg_is_ignored_opcode(cur->op->opcode)) {
680+
continue;
681+
}
682+
672683
insert_idx = cur->op->lineno;
673684
}
674685

@@ -680,8 +691,7 @@ static PHP_FUNCTION(phpdbg_end_oplog)
680691
Z_LVAL_P(num)++;
681692
}
682693

683-
cur = cur->next;
684-
} while (cur != NULL);
694+
} while ((cur = cur->next));
685695
}
686696

687697
if (!prev) {

0 commit comments

Comments
 (0)