File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -67,15 +67,16 @@ PHP_METHOD(ObjectID, __construct)
67
67
zend_restore_error_handling (& error_handling TSRMLS_CC );
68
68
69
69
if (id ) {
70
- zend_str_tolower (id , id_len );
71
- if (bson_oid_is_valid (id , id_len )) {
70
+ char * tid = zend_str_tolower_dup (id , id_len );
71
+ if (bson_oid_is_valid (tid , id_len )) {
72
72
bson_oid_t oid ;
73
73
74
- bson_oid_init_from_string (& oid , id );
74
+ bson_oid_init_from_string (& oid , tid );
75
75
bson_oid_to_string (& oid , intern -> oid );
76
76
} else {
77
77
phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s" , "Invalid BSON ID provided" );
78
78
}
79
+ efree (tid );
79
80
} else {
80
81
bson_oid_t oid ;
81
82
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ PHPC-672: ObjectID constructor should not modify string argument's memory
3
+ --SKIPIF--
4
+ <?php require __DIR__ . "/../utils/basic-skipif.inc " ?>
5
+ --FILE--
6
+ <?php
7
+ require_once __DIR__ . "/../utils/basic.inc " ;
8
+
9
+ $ id = '56925B7330616224D0000001 ' ;
10
+ var_dump (new MongoDB \BSON \ObjectID ($ id ));
11
+ var_dump ($ id );
12
+
13
+ $ invalidId = 'T123456 ' ;
14
+ throws (function () use ($ invalidId ) {
15
+ new MongoDB \BSON \ObjectID ($ invalidId );
16
+ }, "MongoDB \\Driver \\Exception \\InvalidArgumentException " );
17
+ var_dump ($ invalidId );
18
+
19
+ ?>
20
+ ===DONE===
21
+ <?php exit (0 ); ?>
22
+ --EXPECTF--
23
+ object(MongoDB\BSON\ObjectID)#%d (%d) {
24
+ ["oid"]=>
25
+ string(24) "56925b7330616224d0000001"
26
+ }
27
+ string(24) "56925B7330616224D0000001"
28
+ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
29
+ string(7) "T123456"
30
+ ===DONE===
You can’t perform that action at this time.
0 commit comments