Skip to content

Commit 22a31bd

Browse files
committed
Add a unlink check for php_stream_bucket_unlink
This is in the same spirit as #13943: low-hanging, not in a hot-path, trivial, removing a limited-linear-write → arbitrary-write primitive, … moreover, given how many filters are available, having some low-hanging hardening there shouldn't hurt. cc @arnaud-lb
1 parent 8cf8751 commit 22a31bd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

main/streams/filter.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
#include <stddef.h>
2323
#include <fcntl.h>
2424

25+
#ifndef ZEND_HEAP_CHECK
26+
# define ZEND_HEAP_CHECK(condition, message) do { \
27+
if (UNEXPECTED(!(condition))) { \
28+
zend_mm_panic(message); \
29+
} \
30+
} while (0)
31+
#endif
32+
2533
#include "php_streams_int.h"
2634

2735
/* Global filter hash, copied to FG(stream_filters) on registration of volatile filter */
@@ -192,11 +200,14 @@ PHPAPI void php_stream_bucket_append(php_stream_bucket_brigade *brigade, php_str
192200
PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket)
193201
{
194202
if (bucket->prev) {
203+
ZEND_HEAP_CHECK(bucket->prev->next == bucket, "Stream bucket list corruption.");
204+
}
195205
bucket->prev->next = bucket->next;
196206
} else if (bucket->brigade) {
197207
bucket->brigade->head = bucket->next;
198208
}
199209
if (bucket->next) {
210+
ZEND_HEAP_CHECK(bucket->next->prev == bucket, "Stream bucket list corruption.");
200211
bucket->next->prev = bucket->prev;
201212
} else if (bucket->brigade) {
202213
bucket->brigade->tail = bucket->prev;

0 commit comments

Comments
 (0)