Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Zend/tests/oss_fuzz_454273637.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--TEST--
OSS-Fuzz #454273637 (UAF with printf optimization and const output)
--FILE--
<?php
printf('%%');
?>
--EXPECT--
%
14 changes: 11 additions & 3 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5009,9 +5009,17 @@ static zend_result zend_compile_func_printf(znode *result, zend_ast_list *args)
* pass in the Zend Optimizer if the result of the printf() is in fact
* unused */
znode copy;
zend_emit_op_tmp(&copy, ZEND_COPY_TMP, &rope_result, NULL);
zend_emit_op(NULL, ZEND_ECHO, &rope_result, NULL);
zend_emit_op_tmp(result, ZEND_STRLEN, &copy, NULL);
if (rope_result.op_type != IS_CONST) {
/* Note: ZEND_COPY_TMP is only valid for TMPVAR. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe ZEND_ASSERT(rope_result.op_type == IS_TMP_VAR);?

ZEND_ASSERT(rope_result.op_type == IS_TMP_VAR);
zend_emit_op_tmp(&copy, ZEND_COPY_TMP, &rope_result, NULL);
zend_emit_op(NULL, ZEND_ECHO, &rope_result, NULL);
zend_emit_op_tmp(result, ZEND_STRLEN, &copy, NULL);
} else {
zend_emit_op(NULL, ZEND_ECHO, &rope_result, NULL);
result->op_type = IS_CONST;
ZVAL_LONG(&result->u.constant, Z_STRLEN(rope_result.u.constant));
}

return SUCCESS;
}
Expand Down