Skip to content

Commit df4474e

Browse files
committed
Merge pull request #1034
2 parents eb9724f + 2f88011 commit df4474e

File tree

10 files changed

+104
-25
lines changed

10 files changed

+104
-25
lines changed

php_phongo.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,14 @@ void phongo_throw_exception_from_bson_error_t_and_reply(bson_error_t* error, con
244244
#endif
245245

246246
zend_throw_exception(php_phongo_commandexception_ce, error->message, error->code TSRMLS_CC);
247-
php_phongo_bson_to_zval(bson_get_data(reply), reply->len, &zv);
248-
247+
if (php_phongo_bson_to_zval(bson_get_data(reply), reply->len, &zv)) {
249248
#if PHP_VERSION_ID >= 70000
250-
phongo_add_exception_prop(ZEND_STRL("resultDocument"), &zv);
249+
phongo_add_exception_prop(ZEND_STRL("resultDocument"), &zv);
251250
#else
252-
phongo_add_exception_prop(ZEND_STRL("resultDocument"), zv TSRMLS_CC);
251+
phongo_add_exception_prop(ZEND_STRL("resultDocument"), zv TSRMLS_CC);
253252
#endif
253+
}
254+
254255
zval_ptr_dtor(&zv);
255256
} else {
256257
zend_throw_exception(phongo_exception_from_mongoc_domain(error->domain, error->code), error->message, error->code TSRMLS_CC);
@@ -1186,7 +1187,10 @@ void php_phongo_server_to_zval(zval* retval, mongoc_server_description_t* sd) /*
11861187

11871188
PHONGO_BSON_INIT_DEBUG_STATE(state);
11881189
bson_iter_document(&iter, &len, &bytes);
1189-
php_phongo_bson_to_zval_ex(bytes, len, &state);
1190+
if (!php_phongo_bson_to_zval_ex(bytes, len, &state)) {
1191+
zval_ptr_dtor(&state.zchild);
1192+
return;
1193+
}
11901194

11911195
#if PHP_VERSION_ID >= 70000
11921196
ADD_ASSOC_ZVAL_EX(retval, "tags", &state.zchild);
@@ -1199,7 +1203,11 @@ void php_phongo_server_to_zval(zval* retval, mongoc_server_description_t* sd) /*
11991203
php_phongo_bson_state state;
12001204

12011205
PHONGO_BSON_INIT_DEBUG_STATE(state);
1202-
php_phongo_bson_to_zval_ex(bson_get_data(is_master), is_master->len, &state);
1206+
1207+
if (!php_phongo_bson_to_zval_ex(bson_get_data(is_master), is_master->len, &state)) {
1208+
zval_ptr_dtor(&state.zchild);
1209+
return;
1210+
}
12031211

12041212
#if PHP_VERSION_ID >= 70000
12051213
ADD_ASSOC_ZVAL_EX(retval, "last_is_master", &state.zchild);

src/BSON/Javascript.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,12 @@ static PHP_METHOD(Javascript, getScope)
180180
php_phongo_bson_state state;
181181

182182
PHONGO_BSON_INIT_STATE(state);
183-
php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state);
183+
184+
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) {
185+
zval_ptr_dtor(&state.zchild);
186+
return;
187+
}
188+
184189
#if PHP_VERSION_ID >= 70000
185190
RETURN_ZVAL(&state.zchild, 0, 1);
186191
#else

src/MongoDB/Command.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ static HashTable* php_phongo_command_get_debug_info(zval* object, int* is_temp T
194194
zval* zv;
195195
#endif
196196

197-
php_phongo_bson_to_zval(bson_get_data(intern->bson), intern->bson->len, &zv);
197+
if (!php_phongo_bson_to_zval(bson_get_data(intern->bson), intern->bson->len, &zv)) {
198+
zval_ptr_dtor(&zv);
199+
goto done;
200+
}
201+
198202
#if PHP_VERSION_ID >= 70000
199203
ADD_ASSOC_ZVAL_EX(&retval, "command", &zv);
200204
#else
@@ -204,6 +208,7 @@ static HashTable* php_phongo_command_get_debug_info(zval* object, int* is_temp T
204208
ADD_ASSOC_NULL_EX(&retval, "command");
205209
}
206210

211+
done:
207212
return Z_ARRVAL(retval);
208213

209214
} /* }}} */

src/MongoDB/Monitoring/CommandFailedEvent.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ PHP_METHOD(CommandFailedEvent, getReply)
107107
return;
108108
}
109109

110-
php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state);
110+
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) {
111+
zval_ptr_dtor(&state.zchild);
112+
return;
113+
}
114+
111115
#if PHP_VERSION_ID >= 70000
112116
RETURN_ZVAL(&state.zchild, 0, 1);
113117
#else
@@ -250,7 +254,11 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zval* object, int
250254
sprintf(operation_id, "%" PRIu64, intern->operation_id);
251255
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
252256

253-
php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state);
257+
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) {
258+
zval_ptr_dtor(&reply_state.zchild);
259+
goto done;
260+
}
261+
254262
#if PHP_VERSION_ID >= 70000
255263
ADD_ASSOC_ZVAL(&retval, "reply", &reply_state.zchild);
256264
#else
@@ -275,6 +283,7 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zval* object, int
275283
#endif
276284
}
277285

286+
done:
278287
return Z_ARRVAL(retval);
279288
} /* }}} */
280289
/* }}} */

src/MongoDB/Monitoring/CommandStartedEvent.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ PHP_METHOD(CommandStartedEvent, getCommand)
4141
return;
4242
}
4343

44-
php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &state);
44+
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &state)) {
45+
zval_ptr_dtor(&state.zchild);
46+
return;
47+
}
48+
4549
#if PHP_VERSION_ID >= 70000
4650
RETURN_ZVAL(&state.zchild, 0, 1);
4751
#else
@@ -214,7 +218,11 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zval* object, in
214218
*is_temp = 1;
215219
array_init_size(&retval, 6);
216220

217-
php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &command_state);
221+
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &command_state)) {
222+
zval_ptr_dtor(&command_state.zchild);
223+
goto done;
224+
}
225+
218226
#if PHP_VERSION_ID >= 70000
219227
ADD_ASSOC_ZVAL(&retval, "command", &command_state.zchild);
220228
#else
@@ -245,6 +253,7 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zval* object, in
245253
#endif
246254
}
247255

256+
done:
248257
return Z_ARRVAL(retval);
249258
} /* }}} */
250259
/* }}} */

src/MongoDB/Monitoring/CommandSucceededEvent.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ PHP_METHOD(CommandSucceededEvent, getReply)
8888
return;
8989
}
9090

91-
php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state);
91+
if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) {
92+
zval_ptr_dtor(&state.zchild);
93+
return;
94+
}
95+
9296
#if PHP_VERSION_ID >= 70000
9397
RETURN_ZVAL(&state.zchild, 0, 1);
9498
#else
@@ -217,7 +221,11 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zval* object,
217221
sprintf(operation_id, "%" PRIu64, intern->operation_id);
218222
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
219223

220-
php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state);
224+
if (php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) {
225+
zval_ptr_dtor(&reply_state.zchild);
226+
goto done;
227+
}
228+
221229
#if PHP_VERSION_ID >= 70000
222230
ADD_ASSOC_ZVAL(&retval, "reply", &reply_state.zchild);
223231
#else
@@ -242,6 +250,7 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zval* object,
242250
#endif
243251
}
244252

253+
done:
245254
return Z_ARRVAL(retval);
246255
} /* }}} */
247256
/* }}} */

src/MongoDB/Query.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,11 @@ static HashTable* php_phongo_query_get_debug_info(zval* object, int* is_temp TSR
455455
zval* zv;
456456
#endif
457457

458-
php_phongo_bson_to_zval(bson_get_data(intern->filter), intern->filter->len, &zv);
458+
if (!php_phongo_bson_to_zval(bson_get_data(intern->filter), intern->filter->len, &zv)) {
459+
zval_ptr_dtor(&zv);
460+
goto done;
461+
}
462+
459463
#if PHP_VERSION_ID >= 70000
460464
ADD_ASSOC_ZVAL_EX(&retval, "filter", &zv);
461465
#else
@@ -472,7 +476,11 @@ static HashTable* php_phongo_query_get_debug_info(zval* object, int* is_temp TSR
472476
zval* zv;
473477
#endif
474478

475-
php_phongo_bson_to_zval(bson_get_data(intern->opts), intern->opts->len, &zv);
479+
if (!php_phongo_bson_to_zval(bson_get_data(intern->opts), intern->opts->len, &zv)) {
480+
zval_ptr_dtor(&zv);
481+
goto done;
482+
}
483+
476484
#if PHP_VERSION_ID >= 70000
477485
ADD_ASSOC_ZVAL_EX(&retval, "options", &zv);
478486
#else
@@ -499,6 +507,7 @@ static HashTable* php_phongo_query_get_debug_info(zval* object, int* is_temp TSR
499507
ADD_ASSOC_NULL_EX(&retval, "readConcern");
500508
}
501509

510+
done:
502511
return Z_ARRVAL(retval);
503512

504513
} /* }}} */

src/MongoDB/ReadPreference.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,12 @@ static PHP_METHOD(ReadPreference, getTagSets)
362362
php_phongo_bson_state state;
363363

364364
PHONGO_BSON_INIT_DEBUG_STATE(state);
365-
php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state);
365+
366+
if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) {
367+
zval_ptr_dtor(&state.zchild);
368+
return;
369+
}
370+
366371
#if PHP_VERSION_ID >= 70000
367372
RETURN_ZVAL(&state.zchild, 0, 1);
368373
#else
@@ -436,15 +441,16 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zval* object, bo
436441
PHONGO_BSON_INIT_STATE(state);
437442
state.map.root_type = PHONGO_TYPEMAP_NATIVE_ARRAY;
438443

439-
php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state);
444+
if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) {
445+
zval_ptr_dtor(&state.zchild);
446+
goto done;
447+
}
448+
440449
#if PHP_VERSION_ID >= 70000
441-
Z_ADDREF(state.zchild);
442450
zend_hash_str_update(props, "tags", sizeof("tags") - 1, &state.zchild);
443451
#else
444-
Z_ADDREF_P(state.zchild);
445452
zend_hash_update(props, "tags", sizeof("tags"), &state.zchild, sizeof(state.zchild), NULL);
446453
#endif
447-
zval_ptr_dtor(&state.zchild);
448454
}
449455

450456
if (mongoc_read_prefs_get_max_staleness_seconds(intern->read_preference) != MONGOC_NO_MAX_STALENESS) {
@@ -463,6 +469,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zval* object, bo
463469
#endif
464470
}
465471

472+
done:
466473
return props;
467474
} /* }}} */
468475

@@ -525,7 +532,12 @@ static PHP_METHOD(ReadPreference, serialize)
525532
php_phongo_bson_state state;
526533

527534
PHONGO_BSON_INIT_DEBUG_STATE(state);
528-
php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state);
535+
536+
if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) {
537+
zval_ptr_dtor(&state.zchild);
538+
return;
539+
}
540+
529541
#if PHP_VERSION_ID >= 70000
530542
ADD_ASSOC_ZVAL_EX(&retval, "tags", &state.zchild);
531543
#else

src/MongoDB/Session.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,10 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
560560

561561
lsid = mongoc_client_session_get_lsid(intern->client_session);
562562

563-
php_phongo_bson_to_zval_ex(bson_get_data(lsid), lsid->len, &state);
563+
if (!php_phongo_bson_to_zval_ex(bson_get_data(lsid), lsid->len, &state)) {
564+
zval_ptr_dtor(&state.zchild);
565+
goto done;
566+
}
564567

565568
#if PHP_VERSION_ID >= 70000
566569
ADD_ASSOC_ZVAL_EX(&retval, "logicalSessionId", &state.zchild);
@@ -580,7 +583,11 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
580583
php_phongo_bson_state state;
581584

582585
PHONGO_BSON_INIT_DEBUG_STATE(state);
583-
php_phongo_bson_to_zval_ex(bson_get_data(cluster_time), cluster_time->len, &state);
586+
587+
if (!php_phongo_bson_to_zval_ex(bson_get_data(cluster_time), cluster_time->len, &state)) {
588+
zval_ptr_dtor(&state.zchild);
589+
goto done;
590+
}
584591

585592
#if PHP_VERSION_ID >= 70000
586593
ADD_ASSOC_ZVAL_EX(&retval, "clusterTime", &state.zchild);
@@ -650,6 +657,7 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T
650657
ADD_ASSOC_NULL_EX(&retval, "server");
651658
}
652659

660+
done:
653661
return Z_ARRVAL(retval);
654662
} /* }}} */
655663
/* }}} */

src/MongoDB/WriteResult.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,11 @@ static HashTable* php_phongo_writeresult_get_debug_info(zval* object, int* is_te
425425

426426
PHONGO_BSON_INIT_DEBUG_STATE(state);
427427
bson_iter_array(&iter, &len, &data);
428-
php_phongo_bson_to_zval_ex(data, len, &state);
428+
if (!php_phongo_bson_to_zval_ex(data, len, &state)) {
429+
zval_ptr_dtor(&state.zchild);
430+
goto done;
431+
}
432+
429433
#if PHP_VERSION_ID >= 70000
430434
ADD_ASSOC_ZVAL_EX(&retval, "upsertedIds", &state.zchild);
431435
#else
@@ -491,6 +495,7 @@ static HashTable* php_phongo_writeresult_get_debug_info(zval* object, int* is_te
491495
ADD_ASSOC_NULL_EX(&retval, "writeConcern");
492496
}
493497

498+
done:
494499
return Z_ARRVAL(retval);
495500
} /* }}} */
496501
/* }}} */

0 commit comments

Comments
 (0)