Skip to content

Commit 556573b

Browse files
committed
Fix php_exec() output length
If trailing whitespace is stripped, we have to propagate the change of `bufl` back to php_exec().
1 parent 3e6667d commit 556573b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ext/standard/exec.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static size_t strip_trailing_whitespace(char *buf, size_t bufl) {
9191
return bufl;
9292
}
9393

94-
static void handle_line(int type, zval *array, char *buf, size_t bufl) {
94+
static size_t handle_line(int type, zval *array, char *buf, size_t bufl) {
9595
if (type == 1) {
9696
PHPWRITE(buf, bufl);
9797
if (php_output_get_level() < 1) {
@@ -101,6 +101,7 @@ static void handle_line(int type, zval *array, char *buf, size_t bufl) {
101101
bufl = strip_trailing_whitespace(buf, bufl);
102102
add_next_index_stringl(array, buf, bufl);
103103
}
104+
return bufl;
104105
}
105106

106107
/* {{{ php_exec
@@ -160,13 +161,13 @@ PHPAPI int php_exec(int type, char *cmd, zval *array, zval *return_value)
160161
bufl += b - buf;
161162
}
162163

163-
handle_line(type, array, buf, bufl);
164+
bufl = handle_line(type, array, buf, bufl);
164165
b = buf;
165166
}
166167
if (bufl) {
167168
if (buf != b) {
168169
/* Process remaining output */
169-
handle_line(type, array, buf, bufl);
170+
bufl = handle_line(type, array, buf, bufl);
170171
}
171172

172173
/* Return last line from the shell command */

0 commit comments

Comments
 (0)