Skip to content

Commit 9588997

Browse files
committed
Fix phpGH-14553: Bug in phpdbg8.3 (also 8.1 and 8.2) echo output - trimmed at NULL byte (?)
This broke in 6318040 when phpdbg stopped using its custom printing routines. By relying on standard printing routines, the embedded NUL bytes are causing the strings to be cut off, even when using %.*s. Solve this by going straight to the output routine, which is what the printf routine would've done anyway. Closes phpGH-14822.
1 parent 39ed999 commit 9588997

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ PHP NEWS
3131
- PHPDBG:
3232
. Fixed bug GH-14596 (crashes with ASAN and ZEND_RC_DEBUG=1).
3333
(David Carlier)
34+
. Fixed bug GH-14553 (echo output trimmed at NULL byte). (nielsdos)
3435

3536
- Shmop:
3637
. Fixed bug GH-14537 (shmop Windows 11 crashes the process). (nielsdos)

sapi/phpdbg/phpdbg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ static void php_sapi_phpdbg_register_vars(zval *track_vars_array) /* {{{ */
845845

846846
static inline size_t php_sapi_phpdbg_ub_write(const char *message, size_t length) /* {{{ */
847847
{
848-
return phpdbg_script(P_STDOUT, "%.*s", (int) length, message);
848+
return phpdbg_process_print(PHPDBG_G(io)[PHPDBG_STDOUT].fd, P_STDOUT, message, (int) length);
849849
} /* }}} */
850850

851851
/* beginning of struct, see main/streams/plain_wrapper.c line 111 */

sapi/phpdbg/phpdbg_out.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ PHPDBG_API int _phpdbg_asprintf(char **buf, const char *format, ...) {
4040
return ret;
4141
}
4242

43-
static int phpdbg_process_print(int fd, int type, const char *msg, int msglen) {
43+
int phpdbg_process_print(int fd, int type, const char *msg, int msglen) {
4444
char *msgout = NULL;
4545
int msgoutlen = FAILURE;
4646

sapi/phpdbg/phpdbg_out.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ PHPDBG_API void phpdbg_free_err_buf(void);
5959
PHPDBG_API void phpdbg_activate_err_buf(bool active);
6060
PHPDBG_API int phpdbg_output_err_buf(const char *strfmt, ...);
6161

62+
int phpdbg_process_print(int fd, int type, const char *msg, int msglen);
63+
6264

6365
/* {{{ For separation */
6466
#define SEPARATE "------------------------------------------------" /* }}} */

sapi/phpdbg/tests/gh10715.phpt

-45 Bytes
Binary file not shown.

sapi/phpdbg/tests/gh14553.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-14553 (Bug in phpdbg8.3 (also 8.1 and 8.2) echo output - trimmed at NULL byte (?))
3+
--PHPDBG--
4+
r
5+
q
6+
--FILE--
7+
<?php
8+
echo "hello\0world";
9+
?>
10+
--EXPECTF--
11+
[Successful compilation of %s]
12+
prompt> hello%0world
13+
[Script ended normally]
14+
prompt>

0 commit comments

Comments
 (0)