You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

126 lines
3.6 KiB

From 8763c6090d627d8bb0ee1d030c30e58f406be9ce Mon Sep 17 00:00:00 2001
From: Stanislav Malyshev <stas@php.net>
Date: Wed, 3 Aug 2016 00:30:12 -0700
Subject: [PATCH] Fix bug #72681 - consume data even if we're not storing them
---
ext/session/session.c | 25 ++++++++++++++++++-------
ext/session/tests/bug72681.phpt | 16 ++++++++++++++++
2 files changed, 34 insertions(+), 7 deletions(-)
create mode 100644 ext/session/tests/bug72681.phpt
Index: php5-5.4.45/ext/session/session.c
===================================================================
--- php5-5.4.45.orig/ext/session/session.c 2016-08-29 20:20:40.000000000 +0200
+++ php5-5.4.45/ext/session/session.c 2016-08-29 20:20:40.000000000 +0200
@@ -829,11 +829,13 @@
int namelen;
int has_value;
php_unserialize_data_t var_hash;
+ int skip = 0;
PHP_VAR_UNSERIALIZE_INIT(var_hash);
for (p = val; p < endptr; ) {
zval **tmp;
+ skip = 0;
namelen = ((unsigned char)(*p)) & (~PS_BIN_UNDEF);
if (namelen < 0 || namelen > PS_BIN_MAX || (p + namelen) >= endptr) {
@@ -849,22 +851,25 @@
if (zend_hash_find(&EG(symbol_table), name, namelen + 1, (void **) &tmp) == SUCCESS) {
if ((Z_TYPE_PP(tmp) == IS_ARRAY && Z_ARRVAL_PP(tmp) == &EG(symbol_table)) || *tmp == PS(http_session_vars)) {
- efree(name);
- continue;
+ skip = 1;
}
}
if (has_value) {
ALLOC_INIT_ZVAL(current);
if (php_var_unserialize(&current, (const unsigned char **) &p, (const unsigned char *) endptr, &var_hash TSRMLS_CC)) {
- php_set_session_var(name, namelen, current, &var_hash TSRMLS_CC);
+ if (!skip) {
+ php_set_session_var(name, namelen, current, &var_hash TSRMLS_CC);
+ }
} else {
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
return FAILURE;
}
var_push_dtor_no_addref(&var_hash, &current);
}
- PS_ADD_VARL(name, namelen);
+ if (!skip) {
+ PS_ADD_VARL(name, namelen);
+ }
efree(name);
}
@@ -921,6 +926,7 @@
int namelen;
int has_value;
php_unserialize_data_t var_hash;
+ int skip = 0;
PHP_VAR_UNSERIALIZE_INIT(var_hash);
@@ -929,6 +935,7 @@
while (p < endptr) {
zval **tmp;
q = p;
+ skip = 0;
while (*q != PS_DELIMITER) {
if (++q >= endptr) goto break_outer_loop;
}
@@ -945,14 +952,16 @@
if (zend_hash_find(&EG(symbol_table), name, namelen + 1, (void **) &tmp) == SUCCESS) {
if ((Z_TYPE_PP(tmp) == IS_ARRAY && Z_ARRVAL_PP(tmp) == &EG(symbol_table)) || *tmp == PS(http_session_vars)) {
- goto skip;
+ skip = 1;
}
}
if (has_value) {
ALLOC_INIT_ZVAL(current);
if (php_var_unserialize(&current, (const unsigned char **) &q, (const unsigned char *) endptr, &var_hash TSRMLS_CC)) {
- php_set_session_var(name, namelen, current, &var_hash TSRMLS_CC);
+ if (!skip) {
+ php_set_session_var(name, namelen, current, &var_hash TSRMLS_CC);
+ }
} else {
var_push_dtor_no_addref(&var_hash, &current);
efree(name);
@@ -961,7 +970,9 @@
}
var_push_dtor_no_addref(&var_hash, &current);
}
- PS_ADD_VARL(name, namelen);
+ if (!skip) {
+ PS_ADD_VARL(name, namelen);
+ }
skip:
efree(name);
Index: php5-5.4.45/ext/session/tests/bug72681.phpt
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ php5-5.4.45/ext/session/tests/bug72681.phpt 2016-08-29 20:20:40.000000000 +0200
@@ -0,0 +1,16 @@
+--TEST--
+Bug #72681: PHP Session Data Injection Vulnerability
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--FILE--
+<?php
+ini_set('session.serialize_handler', 'php');
+session_start();
+$_SESSION['_SESSION'] = 'ryat|O:8:"stdClass":0:{}';
+session_write_close();
+session_start();
+var_dump($_SESSION);
+?>
+--EXPECT--
+array(0) {
+}