Skip to content
Merged
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
2 changes: 1 addition & 1 deletion ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static zend_always_inline uint32_t prop_get_flags(const property_reference *ref)

static inline bool is_closure_invoke(const zend_class_entry *ce, const zend_string *lcname) {
return ce == zend_ce_closure
&& zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME);
&& zend_string_equals(lcname, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE));
}

static zend_function *_copy_function(zend_function *fptr) /* {{{ */
Expand Down
11 changes: 1 addition & 10 deletions ext/session/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "ext/standard/url_scanner_ex.h"
#include "ext/standard/info.h"
#include "zend_smart_str.h"
#include "zend_exceptions.h"
#include "ext/standard/url.h"
#include "ext/standard/basic_functions.h"
#include "ext/standard/head.h"
Expand Down Expand Up @@ -1725,16 +1724,8 @@ PHPAPI php_session_status php_get_session_status(void)
static bool php_session_abort(void)
{
if (PS(session_status) == php_session_active) {
if ((PS(mod_data) || PS(mod_user_implemented)) && PS(mod)->s_close) {
zend_object *old_exception = EG(exception);
EG(exception) = NULL;

if (PS(mod_data) || PS(mod_user_implemented)) {
PS(mod)->s_close(&PS(mod_data));
if (!EG(exception)) {
EG(exception) = old_exception;
} else if (old_exception) {
zend_exception_set_previous(EG(exception), old_exception);
}
}
PS(session_status) = php_session_none;
return true;
Expand Down
35 changes: 0 additions & 35 deletions ext/session/tests/sessionhandler_validateid_return_type.phpt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ var_dump(session_id(), $oldHandler, ini_get('session.save_handler'), $handler->i
--EXPECTF--
*** Testing session_set_save_handler() : incorrect arguments for existing handler open ***
Open:

Warning: SessionHandler::close(): Parent session handler is not open in %s on line %d
SessionHandler::open() expects exactly 2 arguments, 0 given

Warning: Undefined global variable $_SESSION in %s on line %d
Expand Down
15 changes: 5 additions & 10 deletions ext/soap/php_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -2439,13 +2439,7 @@ static xmlNodePtr to_xml_array(encodeTypePtr type, zval *data, int style, xmlNod
if (style == SOAP_ENCODED) {
if (soap_version == SOAP_1_1) {
smart_str_0(&array_type);
#if defined(__GNUC__) && __GNUC__ >= 11
ZEND_DIAGNOSTIC_IGNORED_START("-Wstringop-overread")
#endif
bool is_xsd_any_type = strcmp(ZSTR_VAL(array_type.s),"xsd:anyType") == 0;
#if defined(__GNUC__) && __GNUC__ >= 11
ZEND_DIAGNOSTIC_IGNORED_END
#endif
bool is_xsd_any_type = zend_string_equals_literal(array_type.s, "xsd:anyType");
if (is_xsd_any_type) {
smart_str_free(&array_type);
smart_str_appendl(&array_type,"xsd:ur-type",sizeof("xsd:ur-type")-1);
Expand Down Expand Up @@ -2529,19 +2523,20 @@ static zval *to_zval_array(zval *ret, encodeTypePtr type, xmlNodePtr data)
xmlNsPtr nsptr;

parse_namespace(attr->children->content, &type, &ns);
char *type_dup = estrdup(type);
nsptr = xmlSearchNs(attr->doc, attr->parent, BAD_CAST(ns));

end = strrchr(type,'[');
end = strrchr(type_dup,'[');
if (end) {
*end = '\0';
dimension = calc_dimension(end+1);
dims = get_position(dimension, end+1);
}
if (nsptr != NULL) {
enc = get_encoder(SOAP_GLOBAL(sdl), (char*)nsptr->href, type);
enc = get_encoder(SOAP_GLOBAL(sdl), (char*)nsptr->href, type_dup);
}
if (ns) {efree(ns);}

if (type_dup) efree(type_dup);
} else if ((attr = get_soap_enc_attribute(data->properties,"itemType")) &&
attr->children &&
attr->children->content) {
Expand Down
10 changes: 5 additions & 5 deletions ext/soap/php_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,22 +1014,22 @@ int make_http_soap_request(
char *eqpos = strstr(cookie, "=");
char *sempos = strstr(cookie, ";");
if (eqpos != NULL && (sempos == NULL || sempos > eqpos)) {
size_t cookie_len;
zval zcookie;
size_t cookie_value_len;

if (sempos != NULL) {
cookie_len = sempos-(eqpos+1);
cookie_value_len = sempos-(eqpos+1);
} else {
cookie_len = strlen(cookie)-(eqpos-cookie)-1;
cookie_value_len = strlen(cookie)-(eqpos-cookie)-1;
}

zend_string *name = zend_string_init(cookie, eqpos - cookie, false);

array_init(&zcookie);
add_index_stringl(&zcookie, 0, eqpos + 1, cookie_len);
add_index_stringl(&zcookie, 0, eqpos + 1, cookie_value_len);

if (sempos != NULL) {
char *options = cookie + cookie_len+1;
char *options = sempos + 1;
while (*options) {
while (*options == ' ') {options++;}
sempos = strstr(options, ";");
Expand Down
61 changes: 61 additions & 0 deletions ext/soap/tests/bugs/cookie_parse_options_offset.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
--TEST--
SOAP Set-Cookie option parsing starts at wrong offset due to variable shadowing
--EXTENSIONS--
soap
--SKIPIF--
<?php
if (!file_exists(__DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc")) {
echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
}
?>
--FILE--
<?php

include __DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc";

$args = ["-d", "extension_dir=" . ini_get("extension_dir"), "-d", "extension=" . (substr(PHP_OS, 0, 3) == "WIN" ? "php_" : "") . "soap." . PHP_SHLIB_SUFFIX];
if (php_ini_loaded_file()) {
$args[] = "-c";
$args[] = php_ini_loaded_file();
}

// A 10-char name makes the wrong offset land exactly on the value "path=/evil",
// falsely matching it as a path attribute.
$code = <<<'PHP'
header("Content-Type: text/xml");
header("Set-Cookie: sessionkey=path=/evil;domain=good.com");
echo <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="test-uri">
<SOAP-ENV:Body>
<ns1:testResponse/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XML;
PHP;

php_cli_server_start($code, null, $args);

$client = new SoapClient(null, [
'location' => 'http://' . PHP_CLI_SERVER_ADDRESS . '/test/endpoint',
'uri' => 'test-uri',
'trace' => true,
]);

try {
$client->__soapCall("test", []);
} catch (SoapFault $e) {
// Response parsing may fault, cookies are still stored
}

$cookies = $client->__getCookies();

// path should default to "/test" from the request URI, not "/evil" from the value.
echo "value: " . $cookies['sessionkey'][0] . "\n";
echo "path: " . $cookies['sessionkey'][1] . "\n";
echo "domain: " . $cookies['sessionkey'][2] . "\n";
?>
--EXPECT--
value: path=/evil
path: /test
domain: good.com
8 changes: 5 additions & 3 deletions ext/sysvshm/sysvshm.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,13 @@ PHP_FUNCTION(shm_get_var)
shm_data = &shm_var->mem;

PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (php_var_unserialize(return_value, (const unsigned char **) &shm_data, (unsigned char *) shm_data + shm_var->length, &var_hash) != 1) {
int res = php_var_unserialize(return_value, (const unsigned char **) &shm_data, (unsigned char *) shm_data + shm_var->length, &var_hash);
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
if (res != 1) {
php_error_docref(NULL, E_WARNING, "Variable data in shared memory is corrupted");
RETVAL_FALSE;
zval_ptr_dtor(return_value);
RETURN_FALSE;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
}
/* }}} */

Expand Down
37 changes: 37 additions & 0 deletions ext/sysvshm/tests/shm_get_var_leak.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
shm_get_var() leaks if variable is corrupted
--EXTENSIONS--
sysvshm
ffi
--INI--
ffi.enable=1
--SKIPIF--
<?php
if (!function_exists('ftok')) die('skip needs ftok');
if (PHP_INT_SIZE !== 8) die('skip only for 64-bit');
if (PHP_OS_FAMILY !== 'Linux') die('skip only for decent operating systems');
?>
--FILE--
<?php

$key = ftok(__FILE__, 't');
$s = shm_attach($key, 128);

shm_put_var($s, 0, [1, 2]);

$ffi = FFI::cdef(<<<CODE
int shmget(int, size_t, int);
char *shmat(int, const void *, int);
CODE);
$ptr = $ffi->shmat($ffi->shmget($key, 0, 0), $ffi->new('void *'), 0);

$ptr[0x40 + 13] = 0; // Corrupt first byte of second element of serialized data

var_dump(shm_get_var($s, 0));

shm_remove($s);

?>
--EXPECTF--
Warning: shm_get_var(): Variable data in shared memory is corrupted in %s on line %d
bool(false)
Loading