Skip to content

Commit 8873df8

Browse files
committed
Fix leak in SplObjectStorage unserialization
The result of php_var_unserialize always needs to be destroyed, even if the call failed.
1 parent 81cefab commit 8873df8

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ext/spl/spl_observer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,12 +804,14 @@ SPL_METHOD(SplObjectStorage, unserialize)
804804
}
805805
/* store reference to allow cross-references between different elements */
806806
if (!php_var_unserialize(&entry, &p, s + buf_len, &var_hash)) {
807+
zval_ptr_dtor(&entry);
807808
goto outexcept;
808809
}
809810
if (*p == ',') { /* new version has inf */
810811
++p;
811812
if (!php_var_unserialize(&inf, &p, s + buf_len, &var_hash)) {
812813
zval_ptr_dtor(&entry);
814+
zval_ptr_dtor(&inf);
813815
goto outexcept;
814816
}
815817
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Unserialize leak in SplObjectStorage
3+
--FILE--
4+
<?php
5+
6+
$payload = 'C:16:"SplObjectStorage":113:{x:i:2;O:8:"stdClass":1:{},a:2:{s:4:"prev";i:2;s:4:"next";O:8:"stdClass":0:{}};r:7;,R:2;s:4:"next";;r:3;};m:a:0:{}}';
7+
try {
8+
var_dump(unserialize($payload));
9+
} catch (Exception $e) {
10+
echo $e->getMessage(), "\n";
11+
}
12+
13+
?>
14+
--EXPECTF--
15+
Notice: SplObjectStorage::unserialize(): Unexpected end of serialized data in %s on line %d
16+
Error at offset 24 of 113 bytes

0 commit comments

Comments
 (0)