diff --git a/NEWS b/NEWS index ec32bdfd088..16b10267098 100644 --- a/NEWS +++ b/NEWS @@ -27,7 +27,11 @@ PHP NEWS - PDO_Firebird: . Fixed GH-15604 (Always make input parameters nullable). (sim1984) -27 Aug 2024, PHP 8.4.0beta4 +- Streams: + . Fixed bug GH-15628 (php_stream_memory_get_buffer() not zero-terminated). + (cmb) + +29 Aug 2024, PHP 8.4.0beta4 - Core: . Fixed bug GH-15408 (MSan false-positve on zend_max_execution_timer). diff --git a/main/streams/memory.c b/main/streams/memory.c index 62d36906635..ce11aec382b 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -66,6 +66,7 @@ static ssize_t php_stream_memory_write(php_stream *stream, const char *buf, size if (count) { ZEND_ASSERT(buf != NULL); memcpy(ZSTR_VAL(ms->data) + ms->fpos, (char*) buf, count); + ZSTR_VAL(ms->data)[ZSTR_LEN(ms->data)] = '\0'; ms->fpos += count; } return count; @@ -241,6 +242,7 @@ static int php_stream_memory_set_option(php_stream *stream, int option, int valu size_t old_size = ZSTR_LEN(ms->data); ms->data = zend_string_realloc(ms->data, newsize, 0); memset(ZSTR_VAL(ms->data) + old_size, 0, newsize - old_size); + ZSTR_VAL(ms->data)[ZSTR_LEN(ms->data)] = '\0'; } return PHP_STREAM_OPTION_RETURN_OK; }