Skip to content
Closed
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2018, PHP 5.6.38
23 Oct 2026, PHP 5.6.37-p1

- Core:
. Fixed GHSA-w8hw-w9fx-j79w (Avoid state corruption via bailout).
(CVE-2026-109618) (Arnaud, ilutov)
. Fixed GHSA-6wmf-4rv5-p3rp (Avoid state corruption via bailout).
(CVE-2026-109619) (Arnaud, ilutov)

19 Jul 2018, PHP 5.6.37

Expand Down
109 changes: 50 additions & 59 deletions Zend/zend_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static void zend_mm_panic(const char *message)
#if ZEND_DEBUG && defined(HAVE_KILL) && defined(HAVE_GETPID)
kill(getpid(), SIGSEGV);
#endif
exit(1);
_exit(1);
}

/*******************/
Expand Down Expand Up @@ -1740,6 +1740,41 @@ ZEND_API void zend_mm_shutdown(zend_mm_heap *heap, int full_shutdown, int silent
}
}

ZEND_API void zend_mm_safe_error_ex(const char *format, ...)
{
const char *error_filename;
uint error_lineno;
char buf[1024];
va_list args;
TSRMLS_FETCH();

if (zend_is_compiling(TSRMLS_C)) {
error_filename = zend_get_compiled_filename(TSRMLS_C);
error_lineno = zend_get_compiled_lineno(TSRMLS_C);
} else if (EG(in_execution)) {
error_filename = EG(active_op_array)?EG(active_op_array)->filename:NULL;
error_lineno = EG(opline_ptr)?(*EG(opline_ptr))->lineno:0;
} else {
error_filename = NULL;
error_lineno = 0;
}
if (!error_filename) {
error_filename = "Unknown";
}

va_start(args, format);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);

fprintf(stderr, "\nFatal error: %s in %s on line %d\n", buf, error_filename, error_lineno);
/* See http://support.microsoft.com/kb/190351 */
#ifdef PHP_WIN32
fflush(stderr);
#endif

_exit(1);
}

static void zend_mm_safe_error(zend_mm_heap *heap,
const char *format,
size_t limit,
Expand All @@ -1749,59 +1784,15 @@ static void zend_mm_safe_error(zend_mm_heap *heap,
#endif
size_t size)
{
if (heap->reserve) {
_zend_mm_free_int(heap, heap->reserve ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC);
heap->reserve = NULL;
}
if (heap->overflow == 0) {
const char *error_filename;
uint error_lineno;
TSRMLS_FETCH();
if (zend_is_compiling(TSRMLS_C)) {
error_filename = zend_get_compiled_filename(TSRMLS_C);
error_lineno = zend_get_compiled_lineno(TSRMLS_C);
} else if (EG(in_execution)) {
error_filename = EG(active_op_array)?EG(active_op_array)->filename:NULL;
error_lineno = EG(opline_ptr)?(*EG(opline_ptr))->lineno:0;
} else {
error_filename = NULL;
error_lineno = 0;
}
if (!error_filename) {
error_filename = "Unknown";
}
heap->overflow = 1;
zend_try {
zend_error_noreturn(E_ERROR,
format,
limit,
#if ZEND_DEBUG
filename,
lineno,
#endif
size);
} zend_catch {
if (heap->overflow == 2) {
fprintf(stderr, "\nFatal error: ");
fprintf(stderr,
format,
limit,
(void) heap;

zend_mm_safe_error_ex(format,
limit,
#if ZEND_DEBUG
filename,
lineno,
#endif
size);
fprintf(stderr, " in %s on line %d\n", error_filename, error_lineno);
}
/* See http://support.microsoft.com/kb/190351 */
#ifdef PHP_WIN32
fflush(stderr);
filename,
lineno,
#endif
} zend_end_try();
} else {
heap->overflow = 2;
}
zend_bailout();
size);
}

static zend_mm_free_block *zend_mm_search_large_block(zend_mm_heap *heap, size_t true_size)
Expand Down Expand Up @@ -2472,7 +2463,7 @@ static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
"rm"(offset));

if (UNEXPECTED(overflow)) {
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
zend_mm_safe_error_ex("Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
return 0;
}
return res;
Expand Down Expand Up @@ -2501,7 +2492,7 @@ static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)

#undef LP_SUFF
if (UNEXPECTED(overflow)) {
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
zend_mm_safe_error_ex("Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
return 0;
}
return res;
Expand All @@ -2522,7 +2513,7 @@ static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
"1"(0));

if (UNEXPECTED(overflow)) {
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
zend_mm_safe_error_ex("Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
return 0;
}
return res;
Expand All @@ -2542,7 +2533,7 @@ static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
"r"(offset));

if (UNEXPECTED(overflow)) {
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
zend_mm_safe_error_ex("Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
return 0;
}
return res;
Expand All @@ -2555,7 +2546,7 @@ static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
zend_ulong64 res = (zend_ulong64)nmemb * (zend_ulong64)size + (zend_ulong64)offset;

if (UNEXPECTED(res > (zend_ulong64)0xFFFFFFFFL)) {
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
zend_mm_safe_error_ex("Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
return 0;
}
return (size_t) res;
Expand All @@ -2570,7 +2561,7 @@ static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
double _delta = (double)res - _d;

if (UNEXPECTED((_d + _delta ) != _d)) {
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
zend_mm_safe_error_ex("Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
return 0;
}
return res;
Expand All @@ -2582,7 +2573,7 @@ ZEND_API void *_safe_emalloc_string(size_t nmemb, size_t size, size_t offset ZEN
{
size_t str_size = safe_address(nmemb, size, offset);
if (UNEXPECTED(str_size > INT_MAX)) {
zend_error_noreturn(E_ERROR, "String allocation overflow, max size is %d", INT_MAX);
zend_mm_safe_error_ex("String allocation overflow, max size is %d", INT_MAX);
}
return emalloc_rel(str_size);
}
Expand Down
6 changes: 6 additions & 0 deletions Zend/zend_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ void zend_debug_alloc_output(char *format, ...);
ZEND_API size_t zend_memory_usage(int real_usage TSRMLS_DC);
ZEND_API size_t zend_memory_peak_usage(int real_usage TSRMLS_DC);

#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)
ZEND_API void zend_mm_safe_error_ex(const char *format, ...) __attribute__ ((noreturn));
#else
ZEND_API void zend_mm_safe_error_ex(const char *format, ...);
#endif

END_EXTERN_C()

/* fast cache for zval's */
Expand Down
5 changes: 5 additions & 0 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,17 @@ void shutdown_executor(TSRMLS_D) /* {{{ */
zend_ptr_stack_destroy(&EG(user_error_handlers));
zend_ptr_stack_destroy(&EG(user_exception_handlers));
zend_objects_store_destroy(&EG(objects_store));
EG(objects_store).top = 1;
if (EG(in_autoload)) {
zend_hash_destroy(EG(in_autoload));
FREE_HASHTABLE(EG(in_autoload));
}
} zend_end_try();

/* may be used by zend_error before init_executor */
EG(error_handling) = EH_NORMAL;
EG(exception) = NULL;

zend_shutdown_fpu(TSRMLS_C);

EG(active) = 0;
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_llist.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ ZEND_API void zend_llist_destroy(zend_llist *l)
current = next;
}

l->head = NULL;
l->tail = NULL;
l->count = 0;
}

Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ ZEND_API int add_char_to_string(zval *result, const zval *op1, const zval *op2)
char *buf;

if (UNEXPECTED(length < 0)) {
zend_error(E_ERROR, "String size overflow");
zend_mm_safe_error_ex("String size overflow");
}

buf = str_erealloc(Z_STRVAL_P(op1), length + 1);
Expand All @@ -1419,7 +1419,7 @@ ZEND_API int add_string_to_string(zval *result, const zval *op1, const zval *op2
char *buf;

if (UNEXPECTED(length < 0)) {
zend_error(E_ERROR, "String size overflow");
zend_mm_safe_error_ex("String size overflow");
}

buf = str_erealloc(Z_STRVAL_P(op1), length + 1);
Expand Down Expand Up @@ -1465,7 +1465,7 @@ ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{
if (Z_STRLEN_P(result) < 0 || (int) (Z_STRLEN_P(op1) + Z_STRLEN_P(op2)) < 0) {
efree(Z_STRVAL_P(result));
ZVAL_EMPTY_STRING(result);
zend_error(E_ERROR, "String size overflow");
zend_mm_safe_error_ex("String size overflow");
}

Z_STRVAL_P(result) = safe_erealloc(Z_STRVAL_P(result), res_len, 1, 1);
Expand All @@ -1478,7 +1478,7 @@ ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{
char *buf;

if (Z_STRLEN_P(op1) < 0 || Z_STRLEN_P(op2) < 0 || (int) (Z_STRLEN_P(op1) + Z_STRLEN_P(op2)) < 0) {
zend_error(E_ERROR, "String size overflow");
zend_mm_safe_error_ex("String size overflow");
}
buf = (char *) safe_emalloc(length, 1, 1);

Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_strtod.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ static Bigint * Balloc(int k)
Bigint *rv;

if (k > Kmax) {
zend_error(E_ERROR, "Balloc() allocation exceeds list boundary");
zend_mm_safe_error_ex("Balloc() allocation exceeds list boundary");
}

_THREAD_PRIVATE_MUTEX_LOCK(dtoa_mutex);
Expand All @@ -490,7 +490,7 @@ static Bigint * Balloc(int k)
rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(Long));
if (!rv) {
_THREAD_PRIVATE_MUTEX_UNLOCK(dtoa_mutex);
zend_error(E_ERROR, "Balloc() failed to allocate memory");
zend_mm_safe_error_ex("Balloc() failed to allocate memory");
}
rv->k = k;
rv->maxwds = x;
Expand Down
4 changes: 2 additions & 2 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ int zend_sprintf(char *buffer, const char *format, ...);

PHP_MAJOR_VERSION=5
PHP_MINOR_VERSION=6
PHP_RELEASE_VERSION=38
PHP_EXTRA_VERSION="-dev"
PHP_RELEASE_VERSION=37
PHP_EXTRA_VERSION="-p1"
PHP_VERSION="$PHP_MAJOR_VERSION.$PHP_MINOR_VERSION.$PHP_RELEASE_VERSION$PHP_EXTRA_VERSION"
PHP_VERSION_ID=`expr [$]PHP_MAJOR_VERSION \* 10000 + [$]PHP_MINOR_VERSION \* 100 + [$]PHP_RELEASE_VERSION`

Expand Down
2 changes: 1 addition & 1 deletion ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -2669,7 +2669,7 @@ static int php_session_rfc1867_callback(unsigned int event, void *event_data, vo
if (php_session_rfc1867_orig_callback) {
retval = php_session_rfc1867_orig_callback(event, event_data, extra TSRMLS_CC);
}
if (!PS(rfc1867_enabled)) {
if (!PS(rfc1867_enabled) || 1) {
return retval;
}

Expand Down
5 changes: 5 additions & 0 deletions main/SAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,18 +528,23 @@ SAPI_API void sapi_deactivate(TSRMLS_D)
}
if (SG(request_info).auth_user) {
efree(SG(request_info).auth_user);
SG(request_info).auth_user = NULL;
}
if (SG(request_info).auth_password) {
efree(SG(request_info).auth_password);
SG(request_info).auth_password = NULL;
}
if (SG(request_info).auth_digest) {
efree(SG(request_info).auth_digest);
SG(request_info).auth_digest = NULL;
}
if (SG(request_info).content_type_dup) {
efree(SG(request_info).content_type_dup);
SG(request_info).content_type_dup = NULL;
}
if (SG(request_info).current_user) {
efree(SG(request_info).current_user);
SG(request_info).current_user = NULL;
}
if (sapi_module.deactivate) {
sapi_module.deactivate(TSRMLS_C);
Expand Down
6 changes: 6 additions & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ PHP_INI_BEGIN()
PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("max_file_uploads", "20", PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)
PHP_INI_ENTRY("max_multipart_body_parts", "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)

STD_PHP_INI_BOOLEAN("allow_url_fopen", "1", PHP_INI_SYSTEM, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("allow_url_include", "0", PHP_INI_SYSTEM, OnUpdateBool, allow_url_include, php_core_globals, core_globals)
Expand Down Expand Up @@ -1880,6 +1881,8 @@ void php_request_shutdown(void *dummy)
for (i=0; i<NUM_TRACK_VARS; i++) {
if (PG(http_globals)[i]) {
zval_ptr_dtor(&PG(http_globals)[i]);
/* May be accessed before php_request_startup() */
PG(http_globals)[i] = NULL;
}
}
} zend_end_try();
Expand Down Expand Up @@ -1937,6 +1940,9 @@ void php_request_shutdown(void *dummy)
#ifdef HAVE_DTRACE
DTRACE_REQUEST_SHUTDOWN(SAFE_FILENAME(SG(request_info).path_translated), SAFE_FILENAME(SG(request_info).request_uri), (char *)SAFE_FILENAME(SG(request_info).request_method));
#endif /* HAVE_DTRACE */

/* May be accessed before php_request_startup() */
PG(modules_activated) = 0;
}
/* }}} */

Expand Down
Loading
Loading