Skip to content

Commit 0f21cbc

Browse files
nielsdosdevnexen
authored andcommitted
Fix GH-10715: phpdbg heap buffer overflow -- by misuse of the option "--run"
Fixes GH-10715 When a string starting with a NUL character is passed to phpdbg_vprint(), the vasprintf() will return that 0 characters have been printed. This causes msglen == 0. When phpdbg_process_print() is called with a message of length 0, the -1 to check for '\n' will perform an out of bounds read. Since nothing is printed anyway for msglen == 0, it seems best to just skip the printing routine for this case. Closes GH-10720.
1 parent 44e5c04 commit 0f21cbc

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ PHP NEWS
6161
. Fixed bug #60994 (Reading a multibyte CLOB caps at 8192 chars).
6262
(Michael Voříšek)
6363

64+
- PHPDBG:
65+
. Fixed bug GH-10715 (heap buffer overflow on --run option misuse). (nielsdos)
66+
6467
- PGSQL:
6568
. Fix GH-10672 (pg_lo_open segfaults in the strict_types mode). (girgias)
6669

sapi/phpdbg/phpdbg_out.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ PHPDBG_API int phpdbg_vprint(int type, int fd, const char *strfmt, va_list args)
143143
return msglen;
144144
}
145145

146-
len = phpdbg_process_print(fd, type, msg, msglen);
146+
if (UNEXPECTED(msglen == 0)) {
147+
len = 0;
148+
} else {
149+
len = phpdbg_process_print(fd, type, msg, msglen);
150+
}
147151

148152
if (msg) {
149153
free(msg);

sapi/phpdbg/tests/gh10715.phpt

192 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)