Skip to content

Commit ba75d4c

Browse files
committed
Properly escape all filenames when exporting breakpoints
1 parent 57c0773 commit ba75d4c

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

sapi/phpdbg/phpdbg_bp.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "phpdbg_utils.h"
2626
#include "phpdbg_opcode.h"
2727
#include "zend_globals.h"
28+
#include "ext/standard/php_string.h"
2829

2930
ZEND_EXTERN_MODULE_GLOBALS(phpdbg)
3031

@@ -135,10 +136,12 @@ PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str) /* {{{ */
135136

136137
switch (brake->type) {
137138
case PHPDBG_BREAK_FILE: {
139+
zend_string *filename = php_addcslashes(zend_string_init(((phpdbg_breakfile_t*)brake)->filename, strlen(((phpdbg_breakfile_t*)brake)->filename), 0), 1, "\\\"\n", 3);
138140
phpdbg_asprintf(&new_str,
139141
"%sbreak \"%s\":%lu\n", *str,
140-
((phpdbg_breakfile_t*)brake)->filename,
142+
ZSTR_VAL(filename),
141143
((phpdbg_breakfile_t*)brake)->line);
144+
zend_string_release(filename);
142145
} break;
143146

144147
case PHPDBG_BREAK_SYM: {
@@ -170,10 +173,12 @@ PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str) /* {{{ */
170173
} break;
171174

172175
case PHPDBG_BREAK_FILE_OPLINE: {
176+
zend_string *filename = php_addcslashes(zend_string_init(((phpdbg_breakopline_t*)brake)->class_name, strlen(((phpdbg_breakopline_t*)brake)->class_name), 0), 1, "\\\"\n", 3);
173177
phpdbg_asprintf(&new_str,
174-
"%sbreak %s:#%llu\n", *str,
175-
((phpdbg_breakopline_t*)brake)->class_name,
178+
"%sbreak \"%s\":#%llu\n", *str,
179+
filename,
176180
((phpdbg_breakopline_t*)brake)->opline_num);
181+
zend_string_release(filename);
177182
} break;
178183

179184
case PHPDBG_BREAK_OPCODE: {
@@ -199,12 +204,14 @@ PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str) /* {{{ */
199204
conditional->code);
200205
break;
201206

202-
case FILE_PARAM:
207+
case FILE_PARAM: {
208+
zend_string *filename = php_addcslashes(zend_string_init(conditional->param.file.name, strlen(conditional->param.file.name), 0), 1, "\\\"\n", 3);
203209
phpdbg_asprintf(&new_str,
204-
"%sbreak at %s:%lu if %s\n", *str,
210+
"%sbreak at \"%s\":%lu if %s\n", *str,
205211
conditional->param.file.name, conditional->param.file.line,
206212
conditional->code);
207-
break;
213+
zend_string_release(filename);
214+
} break;
208215

209216
default: { /* do nothing */ } break;
210217
}

sapi/phpdbg/phpdbg_lexer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ int phpdbg_lex (phpdbg_param_t* yylval) {
534534
#line 161 "sapi/phpdbg/phpdbg_lexer.l"
535535
{
536536
phpdbg_init_param(yylval, STR_PARAM);
537-
yylval->str = estrndup(yytext + (*yytext == '\'' || *yytext == '\"'), yyleng - unescape_string(yytext));
537+
yylval->str = estrndup(yytext, yyleng - unescape_string(yytext));
538538
yylval->len = yyleng;
539539
return T_ID;
540540
}

sapi/phpdbg/phpdbg_lexer.l

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ INPUT ("\\"[#"']|["]("\\\\"|"\\"["]|[^\n\000"])+["]|[']("\\"[']|"\\\\"|[^\
160160
161161
<NORMAL>{GENERIC_ID} {
162162
phpdbg_init_param(yylval, STR_PARAM);
163-
yylval->str = estrndup(yytext + (*yytext == '\'' || *yytext == '\"'), yyleng - unescape_string(yytext));
163+
yylval->str = estrndup(yytext, yyleng - unescape_string(yytext));
164164
yylval->len = yyleng;
165165
return T_ID;
166166
}

sapi/phpdbg/phpdbg_utils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ char *phpdbg_short_zval_print(zval *zv, int maxlen) /* {{{ */
807807
break;
808808
case IS_STRING: {
809809
int i;
810-
zend_string *str = php_addcslashes(Z_STR_P(zv), 0, "\\\"", 2);
810+
zend_string *str = php_addcslashes(Z_STR_P(zv), 0, "\\\"\n\t\0", 5);
811811
for (i = 0; i < ZSTR_LEN(str); i++) {
812812
if (ZSTR_VAL(str)[i] < 32) {
813813
ZSTR_VAL(str)[i] = ' ';

sapi/phpdbg/tests/exceptions_003.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ prompt> [L0 %s HANDLE_EXCEPTION
2020
>00005: x();
2121
00006: } finally {
2222
00007: print "ok\n";
23-
prompt> [L7 %s ECHO "ok " %s]
23+
prompt> [L7 %s ECHO "ok\n" %s]
2424
>00007: print "ok\n";
2525
00008: }
2626
00009: } catch (Error $e) {
@@ -30,7 +30,7 @@ prompt> ok
3030
>00005: x();
3131
00006: } finally {
3232
00007: print "ok\n";
33-
prompt> [L10 %s ECHO "caught " %s]
33+
prompt> [L10 %s ECHO "caught\n" %s]
3434
>00010: print "caught\n";
3535
00011: }
3636
00012:

sapi/phpdbg/tests/info_001.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ prompt> string(4) "test"
3232
00017:
3333
prompt> [Variables in foo() (1)]
3434
Address Refs Type Variable
35-
%s 1 string $baz
35+
%s %d string $baz
3636
string (4) "test"
3737
prompt> [Superglobal variables (8)]
3838
Address Refs Type Variable

0 commit comments

Comments
 (0)