Skip to content

Commit 4f1103e

Browse files
committed
Fix GH-12675: MEMORY_LEAK in phpdbg_prompt.c
Have to use file_put_contents() instead of --FILE-- because we have to actually load it using the exec command, *and* have to make multiple files, and note that we can only load files relative from the current directory, so we can't rely on files being in the sapi/phpdbg/tests folder. Closes GH-12680.
1 parent 6d59640 commit 4f1103e

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ PHP NEWS
88
- PCRE:
99
. Fixed bug GH-12628 (The gh11374 test fails on Alpinelinux). (nielsdos)
1010

11+
- PHPDBG:
12+
. Fixed bug GH-12675 (MEMORY_LEAK in phpdbg_prompt.c). (nielsdos)
13+
1114
- Standard:
1215
. Fix memory leak in syslog device handling. (danog)
1316
. Fixed bug GH-12621 (browscap segmentation fault when configured in the

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ PHPDBG_COMMAND(exec) /* {{{ */
408408
if ((res_len != PHPDBG_G(exec_len)) || (memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) {
409409
if (PHPDBG_G(in_execution)) {
410410
if (phpdbg_ask_user_permission("Do you really want to stop execution to set a new execution context?") == FAILURE) {
411+
free(res);
411412
return FAILURE;
412413
}
413414
}
@@ -441,6 +442,7 @@ PHPDBG_COMMAND(exec) /* {{{ */
441442

442443
phpdbg_compile();
443444
} else {
445+
free(res);
444446
phpdbg_notice("Execution context not changed");
445447
}
446448
} else {

sapi/phpdbg/tests/gh12675.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
GH-12675 (MEMORY_LEAK in phpdbg_prompt.c)
3+
--INI--
4+
opcache.enable=0
5+
--PHPDBG--
6+
ev file_put_contents("gh12675_1.tmp", "<?php echo 'hi';\necho 2;")
7+
ev file_put_contents("gh12675_2.tmp", "<?php echo 'hi';")
8+
exec nonexistent.php
9+
exec gh12675_1.tmp
10+
exec gh12675_1.tmp
11+
b gh12675_1.tmp:2
12+
r
13+
exec gh12675_2.tmp
14+
n
15+
q
16+
--EXPECTF--
17+
prompt> 24
18+
prompt> 16
19+
prompt> [Cannot stat nonexistent.php, ensure the file exists]
20+
prompt> [Set execution context: %sgh12675_1.tmp]
21+
[Successful compilation of %sgh12675_1.tmp]
22+
prompt> [Execution context not changed]
23+
prompt> [Breakpoint #0 added at %sgh12675_1.tmp:2]
24+
prompt> hi
25+
[Breakpoint #0 at %sgh12675_1.tmp:2, hits: 1]
26+
>00002: echo 2;
27+
prompt> Do you really want to stop execution to set a new execution context? (type y or n): prompt>
28+
--CLEAN--
29+
<?php
30+
@unlink("gh12675_1.tmp");
31+
@unlink("gh12675_2.tmp");
32+
?>

0 commit comments

Comments
 (0)