1
0
mirror of https://github.com/php/php-src.git synced 2026-04-05 07:02:33 +02:00

Initialize UNUSED operands to sentinel value

This makes it more likely that unintentional uses of UNUSED
operands will result in crash rather than some hard to detect
corruption of the call frame.
This commit is contained in:
Nikita Popov
2021-09-15 13:11:08 +02:00
parent e77af8bb9a
commit 19888a69b4
2 changed files with 13 additions and 11 deletions

View File

@@ -724,7 +724,7 @@ static void zend_do_free(znode *op1) /* {{{ */
case ZEND_POST_DEC:
/* convert $i++ to ++$i */
opline->opcode -= 2;
opline->result_type = IS_UNUSED;
SET_UNUSED(opline->result);
return;
case ZEND_ASSIGN:
case ZEND_ASSIGN_DIM:
@@ -740,7 +740,7 @@ static void zend_do_free(znode *op1) /* {{{ */
case ZEND_PRE_DEC_OBJ:
case ZEND_PRE_INC:
case ZEND_PRE_DEC:
opline->result_type = IS_UNUSED;
SET_UNUSED(opline->result);
return;
}
}
@@ -757,10 +757,8 @@ static void zend_do_free(znode *op1) /* {{{ */
&& opline->result.var == op1->u.op.var) {
if (opline->opcode == ZEND_FETCH_THIS) {
opline->opcode = ZEND_NOP;
opline->result_type = IS_UNUSED;
} else {
opline->result_type = IS_UNUSED;
}
SET_UNUSED(opline->result);
} else {
while (opline >= CG(active_op_array)->opcodes) {
if ((opline->opcode == ZEND_FETCH_LIST_R ||
@@ -5103,11 +5101,11 @@ void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline) /* {{{ */
}
opline->opcode = ZEND_JMP;
opline->op1.opline_num = dest->opline_num;
opline->extended_value = 0;
SET_UNUSED(opline->op1);
SET_UNUSED(opline->op2);
SET_UNUSED(opline->result);
opline->op1.opline_num = dest->opline_num;
opline->extended_value = 0;
ZEND_ASSERT(remove_oplines >= 0);
while (remove_oplines--) {
@@ -9394,6 +9392,7 @@ static void zend_compile_const(znode *result, zend_ast *ast) /* {{{ */
opline->op2_type = IS_CONST;
if (is_fully_qualified || !FC(current_namespace)) {
opline->op1.num = 0;
opline->op2.constant = zend_add_const_name_literal(
resolved_name, 0);
} else {

View File

@@ -27,16 +27,19 @@
#include "zend_llist.h"
#define SET_UNUSED(op) op ## _type = IS_UNUSED
#define SET_UNUSED(op) do { \
op ## _type = IS_UNUSED; \
op.num = (uint32_t) -1; \
} while (0)
#define MAKE_NOP(opline) do { \
(opline)->op1.num = 0; \
(opline)->op2.num = 0; \
(opline)->result.num = 0; \
(opline)->opcode = ZEND_NOP; \
(opline)->op1_type = IS_UNUSED; \
(opline)->op2_type = IS_UNUSED; \
(opline)->result_type = IS_UNUSED; \
SET_UNUSED((opline)->op1); \
SET_UNUSED((opline)->op2); \
SET_UNUSED((opline)->result); \
} while (0)
#define RESET_DOC_COMMENT() do { \