Open chibinz opened 6 days ago
That's basically the same issue as #16591 (although a completely different code path).
We could do something like this, but sadly the affected macro is in a public header :-(
diff --git a/ext/session/php_session.h b/ext/session/php_session.h
index 31b96340e82..862b79867b1 100644
--- a/ext/session/php_session.h
+++ b/ext/session/php_session.h
@@ -289,7 +289,10 @@ PHPAPI zend_result php_session_reset_id(void);
zval *struc;
#define PS_ENCODE_LOOP(code) do { \
- HashTable *_ht = Z_ARRVAL_P(Z_REFVAL(PS(http_session_vars))); \
+ zval _zv; \
+ /* protect against user interference */ \
+ ZVAL_COPY(&_zv, Z_REFVAL(PS(http_session_vars))); \
+ HashTable *_ht = Z_ARRVAL(_zv); \
ZEND_HASH_FOREACH_KEY(_ht, num_key, key) { \
if (key == NULL) { \
php_error_docref(NULL, E_WARNING, \
@@ -300,6 +303,7 @@ PHPAPI zend_result php_session_reset_id(void);
code; \
} \
} ZEND_HASH_FOREACH_END(); \
+ zval_ptr_dtor(&_zv); \
} while(0)
PHPAPI ZEND_EXTERN_MODULE_GLOBALS(ps)
diff --git a/ext/session/session.c b/ext/session/session.c
index dd780f4afd4..0f4042b735e 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -966,6 +966,7 @@ PS_SERIALIZER_ENCODE_FUNC(php) /* {{{ */
smart_str buf = {0};
php_serialize_data_t var_hash;
PS_ENCODE_VARS;
+ bool fail = false;
PHP_VAR_SERIALIZE_INIT(var_hash);
@@ -974,12 +975,17 @@ PS_SERIALIZER_ENCODE_FUNC(php) /* {{{ */
if (memchr(ZSTR_VAL(key), PS_DELIMITER, ZSTR_LEN(key))) {
PHP_VAR_SERIALIZE_DESTROY(var_hash);
smart_str_free(&buf);
- return NULL;
+ fail = true;
+ break;
}
smart_str_appendc(&buf, PS_DELIMITER);
php_var_serialize(&buf, struc, &var_hash);
);
+ if (fail) {
+ return NULL;
+ }
+
smart_str_0(&buf);
PHP_VAR_SERIALIZE_DESTROY(var_hash);
We could do something like this, but sadly the affected macro is in a public header :-(
Might still be okay for PHP-8.4, though.
Description
The following code:
Resulted in this output:
PHP Version
PHP 8.5.0-dev
Operating System
No response