]> granicus.if.org Git - php/commitdiff
Fixed bug #70876 (Segmentation fault when regenerating session id with strict mode)
authorXinchen Hui <laruence@gmail.com>
Sat, 7 Nov 2015 15:30:31 +0000 (07:30 -0800)
committerXinchen Hui <laruence@gmail.com>
Sat, 7 Nov 2015 15:30:31 +0000 (07:30 -0800)
NEWS
ext/session/session.c
ext/session/tests/bug70876.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 95aab2c0c193ff00122cd754265a5d0c9cf3bce7..8f3ff128b1ec925adb772eefd628d7285b592b58 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,7 +24,7 @@ PHP                                                                        NEWS
 
 - Session:
   . Fixed bug #70876 (Segmentation fault when regenerating session id with
-    strict mode). (Reeze Xia)
+    strict mode). (Laruence)
 
 - SOAP:
   . Fixed bug #70875 (Segmentation fault if wsdl has no targetNamespace
index 570173a8384347d7cdc16c3809eab835ab186f12..dd8651883dc99a26c098b69e821ef4f63877d436 100644 (file)
@@ -2077,6 +2077,11 @@ static PHP_FUNCTION(session_regenerate_id)
                php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
                RETURN_FALSE;
        }
+       if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) {
+               PS(session_status) = php_session_none;
+               php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
+               RETURN_FALSE;
+       }
        if (PS(use_strict_mode) && PS(mod)->s_validate_sid &&
                PS(mod)->s_validate_sid(&PS(mod_data), PS(id)) == FAILURE) {
                zend_string_release(PS(id));
@@ -2087,11 +2092,6 @@ static PHP_FUNCTION(session_regenerate_id)
                        RETURN_FALSE;
                }
        }
-       if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) {
-               PS(session_status) = php_session_none;
-               php_error_docref(NULL, E_RECOVERABLE_ERROR, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
-               RETURN_FALSE;
-       }
        /* Read is required to make new session data at this point. */
        if (PS(mod)->s_read(&PS(mod_data), PS(id), &data, PS(gc_maxlifetime)) == FAILURE) {
                PS(session_status) = php_session_none;
diff --git a/ext/session/tests/bug70876.phpt b/ext/session/tests/bug70876.phpt
new file mode 100644 (file)
index 0000000..33e0323
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Bug #70876 Segmentation fault when regenerating session id with strict mode
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--INI--
+html_errors=0
+session.save_handler=files
+--FILE--
+<?php
+ini_set('session.use_strict_mode', true);
+session_start();
+session_regenerate_id();
+
+echo "ok";
+?>
+--EXPECT--
+ok
\ No newline at end of file