Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GH-15680: Enhance zend_dump_op_array to Properly Represent Non-Printable Characters in String Literals #17277

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 19 additions & 5 deletions Zend/Optimizer/zend_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "zend_func_info.h"
#include "zend_call_graph.h"
#include "zend_dump.h"
#include "ext/standard/php_string.h"
#include "zend_smart_str.h"

void zend_dump_ht(HashTable *ht)
{
Expand Down Expand Up @@ -66,13 +66,27 @@ void zend_dump_const(const zval *zv)
case IS_DOUBLE:
fprintf(stderr, " float(%g)", Z_DVAL_P(zv));
break;
case IS_STRING:;
zend_string *escaped_string = php_addcslashes(Z_STR_P(zv), "\"\\", 2);
case IS_STRING: {
smart_str escaped_string = {0};
smart_str_append_escaped(&escaped_string, Z_STRVAL_P(zv), Z_STRLEN_P(zv));
smart_str_0(&escaped_string);

fprintf(stderr, " string(\"%s\")", ZSTR_VAL(escaped_string));
fprintf(stderr, " string(\"");

zend_string_release(escaped_string);
/* Also escape '"' */
for (size_t i = 0; i < ZSTR_LEN(escaped_string.s); i++) {
if (ZSTR_VAL(escaped_string.s)[i] == '"') {
fprintf(stderr, "\\\"");
} else {
putc(ZSTR_VAL(escaped_string.s)[i], stderr);
}
}

fprintf(stderr, "\")");

smart_str_free_ex(&escaped_string, false);
break;
}
case IS_ARRAY:
fprintf(stderr, " array(...)");
break;
Expand Down
6 changes: 2 additions & 4 deletions ext/opcache/tests/match/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ test:
; (lines=2, args=0, vars=0, tmps=0)
; (after optimizer)
; %s
0000 ECHO string("No match
")
0000 ECHO string("No match\n")
0001 RETURN null

test2:
; (lines=2, args=0, vars=0, tmps=0)
; (after optimizer)
; %s
0000 ECHO string("No match
")
0000 ECHO string("No match\n")
0001 RETURN null
No match
No match
6 changes: 2 additions & 4 deletions ext/opcache/tests/opt/dce_009.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ Loop::test:
; (lines=3, args=0, vars=0, tmps=0)
; (after optimizer)
; %sdce_009.php:4-10
0000 ECHO string("Start
")
0001 ECHO string("Done
")
0000 ECHO string("Start\n")
0001 ECHO string("Done\n")
0002 RETURN null

Loop::test2:
Expand Down
3 changes: 1 addition & 2 deletions ext/opcache/tests/opt/sccp_032.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ $_main:
0004 INIT_FCALL 1 %d string("var_export")
0005 SEND_VAR CV0($x) 1
0006 DO_ICALL
0007 ECHO string("
")
0007 ECHO string("\n")
0008 JMP 0003
0009 FE_FREE V1
0010 RETURN int(1)
Expand Down
Loading