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)
6767 zend_restore_error_handling (& error_handling TSRMLS_CC );
6868
6969 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 )) {
7272 bson_oid_t oid ;
7373
74- bson_oid_init_from_string (& oid , id );
74+ bson_oid_init_from_string (& oid , tid );
7575 bson_oid_to_string (& oid , intern -> oid );
7676 } else {
7777 phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s" , "Invalid BSON ID provided" );
7878 }
79+ efree (tid );
7980 } else {
8081 bson_oid_t oid ;
8182
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