Merge branch 'PHP-8.2' into PHP-8.3

* PHP-8.2:
  Fix GH-15628: php_stream_memory_get_buffer() not zero-terminated
This commit is contained in:
Christoph M. Becker 2024-09-01 14:56:22 +02:00
commit 5f504f10dd
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
2 changed files with 6 additions and 0 deletions

4
NEWS
View file

@ -27,6 +27,10 @@ PHP NEWS
. Fixed bug GH-15432 (Heap corruption when querying a vector). (cmb, . Fixed bug GH-15432 (Heap corruption when querying a vector). (cmb,
Kamil Tekiela) Kamil Tekiela)
- Streams:
. Fixed bug GH-15628 (php_stream_memory_get_buffer() not zero-terminated).
(cmb)
29 Aug 2024, PHP 8.3.11 29 Aug 2024, PHP 8.3.11
- Core: - Core:

View file

@ -66,6 +66,7 @@ static ssize_t php_stream_memory_write(php_stream *stream, const char *buf, size
if (count) { if (count) {
ZEND_ASSERT(buf != NULL); ZEND_ASSERT(buf != NULL);
memcpy(ZSTR_VAL(ms->data) + ms->fpos, (char*) buf, count); memcpy(ZSTR_VAL(ms->data) + ms->fpos, (char*) buf, count);
ZSTR_VAL(ms->data)[ZSTR_LEN(ms->data)] = '\0';
ms->fpos += count; ms->fpos += count;
} }
return 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); size_t old_size = ZSTR_LEN(ms->data);
ms->data = zend_string_realloc(ms->data, newsize, 0); ms->data = zend_string_realloc(ms->data, newsize, 0);
memset(ZSTR_VAL(ms->data) + old_size, 0, newsize - old_size); 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; return PHP_STREAM_OPTION_RETURN_OK;
} }