Skip to content

Commit 55f519b

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix phpGH-15628: php_stream_memory_get_buffer() not zero-terminated
2 parents a57ce05 + 5f504f1 commit 55f519b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

NEWS

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ PHP NEWS
2727
- PDO_Firebird:
2828
. Fixed GH-15604 (Always make input parameters nullable). (sim1984)
2929

30-
27 Aug 2024, PHP 8.4.0beta4
30+
- Streams:
31+
. Fixed bug GH-15628 (php_stream_memory_get_buffer() not zero-terminated).
32+
(cmb)
33+
34+
29 Aug 2024, PHP 8.4.0beta4
3135

3236
- Core:
3337
. Fixed bug GH-15408 (MSan false-positve on zend_max_execution_timer).

main/streams/memory.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static ssize_t php_stream_memory_write(php_stream *stream, const char *buf, size
6666
if (count) {
6767
ZEND_ASSERT(buf != NULL);
6868
memcpy(ZSTR_VAL(ms->data) + ms->fpos, (char*) buf, count);
69+
ZSTR_VAL(ms->data)[ZSTR_LEN(ms->data)] = '\0';
6970
ms->fpos += count;
7071
}
7172
return count;
@@ -241,6 +242,7 @@ static int php_stream_memory_set_option(php_stream *stream, int option, int valu
241242
size_t old_size = ZSTR_LEN(ms->data);
242243
ms->data = zend_string_realloc(ms->data, newsize, 0);
243244
memset(ZSTR_VAL(ms->data) + old_size, 0, newsize - old_size);
245+
ZSTR_VAL(ms->data)[ZSTR_LEN(ms->data)] = '\0';
244246
}
245247
return PHP_STREAM_OPTION_RETURN_OK;
246248
}

0 commit comments

Comments
 (0)