Skip to content

Add a unlink check for php_stream_bucket_unlink #14339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions main/streams/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,33 @@
#include <stddef.h>
#include <fcntl.h>

#ifndef ZEND_HEAP_CHECK
# define ZEND_HEAP_CHECK(condition, message) do { \
if (UNEXPECTED(!(condition))) { \
zend_heap(message); \
} \
} while (0)
#endif

#include "php_streams_int.h"

/* Global filter hash, copied to FG(stream_filters) on registration of volatile filter */
static HashTable stream_filters_hash;

static ZEND_COLD ZEND_NORETURN void zend_heap(const char *message)
{
fprintf(stderr, "%s\n", message);
/* See http://support.microsoft.com/kb/190351 */
#ifdef ZEND_WIN32
fflush(stderr);
#endif
#if ZEND_DEBUG && defined(HAVE_KILL) && defined(HAVE_GETPID)
kill(getpid(), SIGSEGV);
#endif
abort();
}


/* Should only be used during core initialization */
PHPAPI HashTable *php_get_stream_filters_hash_global(void)
{
Expand Down Expand Up @@ -192,11 +214,13 @@ PHPAPI void php_stream_bucket_append(php_stream_bucket_brigade *brigade, php_str
PHPAPI void php_stream_bucket_unlink(php_stream_bucket *bucket)
{
if (bucket->prev) {
ZEND_HEAP_CHECK(bucket->prev->next == bucket, "Stream bucket list corruption.");
bucket->prev->next = bucket->next;
} else if (bucket->brigade) {
bucket->brigade->head = bucket->next;
}
if (bucket->next) {
ZEND_HEAP_CHECK(bucket->next->prev == bucket, "Stream bucket list corruption.");
bucket->next->prev = bucket->prev;
} else if (bucket->brigade) {
bucket->brigade->tail = bucket->prev;
Expand Down