File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -1103,6 +1103,7 @@ PHP_FUNCTION(fromJSON)
1103
1103
1104
1104
if (bson_init_from_json (& b , (const char * )data , data_len , & error )) {
1105
1105
RETVAL_STRINGL ((const char * ) bson_get_data (& b ), b .len , 1 );
1106
+ bson_destroy (& b );
1106
1107
} else {
1107
1108
RETURN_NULL ();
1108
1109
}
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ PHPC-341: fromJSON() leaks when JSON contains array or object fields
3
+ --SKIPIF--
4
+ <?php require __DIR__ . "/../utils/basic-skipif.inc " ?>
5
+ --FILE--
6
+ <?php
7
+ require_once __DIR__ . "/../utils/basic.inc " ;
8
+
9
+ $ tests = array (
10
+ '{ "foo": "yes", "bar" : false } ' ,
11
+ '{ "foo": "no", "array" : [ 5, 6 ] } ' ,
12
+ '{ "foo": "no", "obj" : { "embedded" : 3.14 } } ' ,
13
+ );
14
+
15
+ foreach ($ tests as $ test ) {
16
+ $ bson = fromJSON ($ test );
17
+ var_dump (toPHP ($ bson ));
18
+ }
19
+
20
+ ?>
21
+ ===DONE===
22
+ <?php exit (0 ); ?>
23
+ --EXPECTF--
24
+ object(stdClass)#%d (2) {
25
+ ["foo"]=>
26
+ string(3) "yes"
27
+ ["bar"]=>
28
+ bool(false)
29
+ }
30
+ object(stdClass)#%d (2) {
31
+ ["foo"]=>
32
+ string(2) "no"
33
+ ["array"]=>
34
+ array(2) {
35
+ [0]=>
36
+ int(5)
37
+ [1]=>
38
+ int(6)
39
+ }
40
+ }
41
+ object(stdClass)#%d (2) {
42
+ ["foo"]=>
43
+ string(2) "no"
44
+ ["obj"]=>
45
+ object(stdClass)#%d (1) {
46
+ ["embedded"]=>
47
+ float(3.14)
48
+ }
49
+ }
50
+ ===DONE===
You can’t perform that action at this time.
0 commit comments