xref: /PHP-7.4/ext/session/tests/bug72562.phpt (revision 80fee637)
1--TEST--
2Bug #72562: Use After Free in unserialize() with Unexpected Session Deserialization
3--SKIPIF--
4<?php include('skipif.inc'); ?>
5--FILE--
6<?php
7
8ini_set('session.serialize_handler', 'php_binary');
9session_start();
10$sess = "\x1xi:1;\x2y";
11session_decode($sess);
12$uns_1 = '{';
13$out_1[] = unserialize($uns_1);
14unset($out_1);
15$fakezval = ptr2str(1122334455);
16$fakezval .= ptr2str(0);
17$fakezval .= "\x00\x00\x00\x00";
18$fakezval .= "\x01";
19$fakezval .= "\x00";
20$fakezval .= "\x00\x00";
21for ($i = 0; $i < 5; $i++) {
22  $v[$i] = $fakezval.$i;
23}
24$uns_2 = 'R:2;';
25$out_2 = unserialize($uns_2);
26var_dump($out_2);
27
28function ptr2str($ptr)
29{
30	$out = '';
31	for ($i = 0; $i < 8; $i++) {
32		$out .= chr($ptr & 0xff);
33		$ptr >>= 8;
34	}
35	return $out;
36}
37?>
38--EXPECTF--
39Warning: session_decode(): Failed to decode session object. Session has been destroyed in %s%ebug72562.php on line %d
40
41Notice: unserialize(): Error at offset 0 of 1 bytes in %s%ebug72562.php on line %d
42
43Notice: unserialize(): Error at offset 4 of 4 bytes in %s%ebug72562.php on line %d
44bool(false)
45