From a176269d42ff26290c7dc47c9c416b8a116d4f68 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 4 Jul 2024 18:07:00 +0200 Subject: [PATCH] Fix GH-14553: Bug in phpdbg8.3 (also 8.1 and 8.2) echo output - trimmed at NULL byte (?) This broke in 6318040df2b6c6f4824b99fd27369179d29ee93b 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. --- sapi/phpdbg/phpdbg.c | 2 +- sapi/phpdbg/phpdbg_out.c | 2 +- sapi/phpdbg/phpdbg_out.h | 2 ++ sapi/phpdbg/tests/gh10715.phpt | Bin 192 -> 147 bytes sapi/phpdbg/tests/gh14553.phpt | 14 ++++++++++++++ 5 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 sapi/phpdbg/tests/gh14553.phpt diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 3aa0b7b60d7e..d9cc8f5e891e 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -845,7 +845,7 @@ static void php_sapi_phpdbg_register_vars(zval *track_vars_array) /* {{{ */ static inline size_t php_sapi_phpdbg_ub_write(const char *message, size_t length) /* {{{ */ { - return phpdbg_script(P_STDOUT, "%.*s", (int) length, message); + return phpdbg_process_print(PHPDBG_G(io)[PHPDBG_STDOUT].fd, P_STDOUT, message, (int) length); } /* }}} */ /* beginning of struct, see main/streams/plain_wrapper.c line 111 */ diff --git a/sapi/phpdbg/phpdbg_out.c b/sapi/phpdbg/phpdbg_out.c index af2f3b98d2ba..63b61fb8eab0 100644 --- a/sapi/phpdbg/phpdbg_out.c +++ b/sapi/phpdbg/phpdbg_out.c @@ -40,7 +40,7 @@ PHPDBG_API int _phpdbg_asprintf(char **buf, const char *format, ...) { return ret; } -static int phpdbg_process_print(int fd, int type, const char *msg, int msglen) { +int phpdbg_process_print(int fd, int type, const char *msg, int msglen) { char *msgout = NULL; int msgoutlen = FAILURE; diff --git a/sapi/phpdbg/phpdbg_out.h b/sapi/phpdbg/phpdbg_out.h index 828e147a1b7e..1a54bb7ec284 100644 --- a/sapi/phpdbg/phpdbg_out.h +++ b/sapi/phpdbg/phpdbg_out.h @@ -59,6 +59,8 @@ PHPDBG_API void phpdbg_free_err_buf(void); PHPDBG_API void phpdbg_activate_err_buf(bool active); PHPDBG_API int phpdbg_output_err_buf(const char *strfmt, ...); +int phpdbg_process_print(int fd, int type, const char *msg, int msglen); + /* {{{ For separation */ #define SEPARATE "------------------------------------------------" /* }}} */ diff --git a/sapi/phpdbg/tests/gh10715.phpt b/sapi/phpdbg/tests/gh10715.phpt index 13edd9afdd8f05df2744b3d5d1257c827d219c40..63d98cae107364557482a3e5b5be52e060f695b8 100644 GIT binary patch delta 48 xcmX@WIGJ%mmZq*QS3yyJZb6BiLbP9gNk(Q~xxLEadBE{jzV&NZb4>FVo7FxoEjACkAVvS4>%uH diff --git a/sapi/phpdbg/tests/gh14553.phpt b/sapi/phpdbg/tests/gh14553.phpt new file mode 100644 index 000000000000..bcf61c0a9fb4 --- /dev/null +++ b/sapi/phpdbg/tests/gh14553.phpt @@ -0,0 +1,14 @@ +--TEST-- +GH-14553 (Bug in phpdbg8.3 (also 8.1 and 8.2) echo output - trimmed at NULL byte (?)) +--PHPDBG-- +r +q +--FILE-- + +--EXPECTF-- +[Successful compilation of %s] +prompt> hello%0world +[Script ended normally] +prompt>