diff --git a/php_phongo.c b/php_phongo.c index d87727277..a9462eac0 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -244,13 +244,14 @@ void phongo_throw_exception_from_bson_error_t_and_reply(bson_error_t* error, con #endif zend_throw_exception(php_phongo_commandexception_ce, error->message, error->code TSRMLS_CC); - php_phongo_bson_to_zval(bson_get_data(reply), reply->len, &zv); - + if (php_phongo_bson_to_zval(bson_get_data(reply), reply->len, &zv)) { #if PHP_VERSION_ID >= 70000 - phongo_add_exception_prop(ZEND_STRL("resultDocument"), &zv); + phongo_add_exception_prop(ZEND_STRL("resultDocument"), &zv); #else - phongo_add_exception_prop(ZEND_STRL("resultDocument"), zv TSRMLS_CC); + phongo_add_exception_prop(ZEND_STRL("resultDocument"), zv TSRMLS_CC); #endif + } + zval_ptr_dtor(&zv); } else { 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) /* PHONGO_BSON_INIT_DEBUG_STATE(state); bson_iter_document(&iter, &len, &bytes); - php_phongo_bson_to_zval_ex(bytes, len, &state); + if (!php_phongo_bson_to_zval_ex(bytes, len, &state)) { + zval_ptr_dtor(&state.zchild); + return; + } #if PHP_VERSION_ID >= 70000 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) /* php_phongo_bson_state state; PHONGO_BSON_INIT_DEBUG_STATE(state); - php_phongo_bson_to_zval_ex(bson_get_data(is_master), is_master->len, &state); + + if (!php_phongo_bson_to_zval_ex(bson_get_data(is_master), is_master->len, &state)) { + zval_ptr_dtor(&state.zchild); + return; + } #if PHP_VERSION_ID >= 70000 ADD_ASSOC_ZVAL_EX(retval, "last_is_master", &state.zchild); diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 4d96f2bbd..57803aaef 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -180,7 +180,12 @@ static PHP_METHOD(Javascript, getScope) php_phongo_bson_state state; PHONGO_BSON_INIT_STATE(state); - php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state); + + if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) { + zval_ptr_dtor(&state.zchild); + return; + } + #if PHP_VERSION_ID >= 70000 RETURN_ZVAL(&state.zchild, 0, 1); #else diff --git a/src/MongoDB/Command.c b/src/MongoDB/Command.c index 9f7dfe17a..f712aad46 100644 --- a/src/MongoDB/Command.c +++ b/src/MongoDB/Command.c @@ -194,7 +194,11 @@ static HashTable* php_phongo_command_get_debug_info(zval* object, int* is_temp T zval* zv; #endif - php_phongo_bson_to_zval(bson_get_data(intern->bson), intern->bson->len, &zv); + if (!php_phongo_bson_to_zval(bson_get_data(intern->bson), intern->bson->len, &zv)) { + zval_ptr_dtor(&zv); + goto done; + } + #if PHP_VERSION_ID >= 70000 ADD_ASSOC_ZVAL_EX(&retval, "command", &zv); #else @@ -204,6 +208,7 @@ static HashTable* php_phongo_command_get_debug_info(zval* object, int* is_temp T ADD_ASSOC_NULL_EX(&retval, "command"); } +done: return Z_ARRVAL(retval); } /* }}} */ diff --git a/src/MongoDB/Monitoring/CommandFailedEvent.c b/src/MongoDB/Monitoring/CommandFailedEvent.c index 59bb08784..3b7ce45ca 100644 --- a/src/MongoDB/Monitoring/CommandFailedEvent.c +++ b/src/MongoDB/Monitoring/CommandFailedEvent.c @@ -107,7 +107,11 @@ PHP_METHOD(CommandFailedEvent, getReply) return; } - php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state); + if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) { + zval_ptr_dtor(&state.zchild); + return; + } + #if PHP_VERSION_ID >= 70000 RETURN_ZVAL(&state.zchild, 0, 1); #else @@ -250,7 +254,11 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zval* object, int sprintf(operation_id, "%" PRIu64, intern->operation_id); ADD_ASSOC_STRING(&retval, "operationId", operation_id); - php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state); + if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) { + zval_ptr_dtor(&reply_state.zchild); + goto done; + } + #if PHP_VERSION_ID >= 70000 ADD_ASSOC_ZVAL(&retval, "reply", &reply_state.zchild); #else @@ -275,6 +283,7 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zval* object, int #endif } +done: return Z_ARRVAL(retval); } /* }}} */ /* }}} */ diff --git a/src/MongoDB/Monitoring/CommandStartedEvent.c b/src/MongoDB/Monitoring/CommandStartedEvent.c index d097b055b..aeed77536 100644 --- a/src/MongoDB/Monitoring/CommandStartedEvent.c +++ b/src/MongoDB/Monitoring/CommandStartedEvent.c @@ -41,7 +41,11 @@ PHP_METHOD(CommandStartedEvent, getCommand) return; } - php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &state); + if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &state)) { + zval_ptr_dtor(&state.zchild); + return; + } + #if PHP_VERSION_ID >= 70000 RETURN_ZVAL(&state.zchild, 0, 1); #else @@ -214,7 +218,11 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zval* object, in *is_temp = 1; array_init_size(&retval, 6); - php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &command_state); + if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &command_state)) { + zval_ptr_dtor(&command_state.zchild); + goto done; + } + #if PHP_VERSION_ID >= 70000 ADD_ASSOC_ZVAL(&retval, "command", &command_state.zchild); #else @@ -245,6 +253,7 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zval* object, in #endif } +done: return Z_ARRVAL(retval); } /* }}} */ /* }}} */ diff --git a/src/MongoDB/Monitoring/CommandSucceededEvent.c b/src/MongoDB/Monitoring/CommandSucceededEvent.c index 7ae366990..df05564d8 100644 --- a/src/MongoDB/Monitoring/CommandSucceededEvent.c +++ b/src/MongoDB/Monitoring/CommandSucceededEvent.c @@ -88,7 +88,11 @@ PHP_METHOD(CommandSucceededEvent, getReply) return; } - php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state); + if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) { + zval_ptr_dtor(&state.zchild); + return; + } + #if PHP_VERSION_ID >= 70000 RETURN_ZVAL(&state.zchild, 0, 1); #else @@ -217,7 +221,11 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zval* object, sprintf(operation_id, "%" PRIu64, intern->operation_id); ADD_ASSOC_STRING(&retval, "operationId", operation_id); - php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state); + if (php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &reply_state)) { + zval_ptr_dtor(&reply_state.zchild); + goto done; + } + #if PHP_VERSION_ID >= 70000 ADD_ASSOC_ZVAL(&retval, "reply", &reply_state.zchild); #else @@ -242,6 +250,7 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zval* object, #endif } +done: return Z_ARRVAL(retval); } /* }}} */ /* }}} */ diff --git a/src/MongoDB/Query.c b/src/MongoDB/Query.c index 74a68a4eb..cc011bb3f 100644 --- a/src/MongoDB/Query.c +++ b/src/MongoDB/Query.c @@ -455,7 +455,11 @@ static HashTable* php_phongo_query_get_debug_info(zval* object, int* is_temp TSR zval* zv; #endif - php_phongo_bson_to_zval(bson_get_data(intern->filter), intern->filter->len, &zv); + if (!php_phongo_bson_to_zval(bson_get_data(intern->filter), intern->filter->len, &zv)) { + zval_ptr_dtor(&zv); + goto done; + } + #if PHP_VERSION_ID >= 70000 ADD_ASSOC_ZVAL_EX(&retval, "filter", &zv); #else @@ -472,7 +476,11 @@ static HashTable* php_phongo_query_get_debug_info(zval* object, int* is_temp TSR zval* zv; #endif - php_phongo_bson_to_zval(bson_get_data(intern->opts), intern->opts->len, &zv); + if (!php_phongo_bson_to_zval(bson_get_data(intern->opts), intern->opts->len, &zv)) { + zval_ptr_dtor(&zv); + goto done; + } + #if PHP_VERSION_ID >= 70000 ADD_ASSOC_ZVAL_EX(&retval, "options", &zv); #else @@ -499,6 +507,7 @@ static HashTable* php_phongo_query_get_debug_info(zval* object, int* is_temp TSR ADD_ASSOC_NULL_EX(&retval, "readConcern"); } +done: return Z_ARRVAL(retval); } /* }}} */ diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 36a7e4e78..4d5e213ff 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -362,7 +362,12 @@ static PHP_METHOD(ReadPreference, getTagSets) php_phongo_bson_state state; PHONGO_BSON_INIT_DEBUG_STATE(state); - php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state); + + if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) { + zval_ptr_dtor(&state.zchild); + return; + } + #if PHP_VERSION_ID >= 70000 RETURN_ZVAL(&state.zchild, 0, 1); #else @@ -436,15 +441,16 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zval* object, bo PHONGO_BSON_INIT_STATE(state); state.map.root_type = PHONGO_TYPEMAP_NATIVE_ARRAY; - php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state); + if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) { + zval_ptr_dtor(&state.zchild); + goto done; + } + #if PHP_VERSION_ID >= 70000 - Z_ADDREF(state.zchild); zend_hash_str_update(props, "tags", sizeof("tags") - 1, &state.zchild); #else - Z_ADDREF_P(state.zchild); zend_hash_update(props, "tags", sizeof("tags"), &state.zchild, sizeof(state.zchild), NULL); #endif - zval_ptr_dtor(&state.zchild); } 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 #endif } +done: return props; } /* }}} */ @@ -525,7 +532,12 @@ static PHP_METHOD(ReadPreference, serialize) php_phongo_bson_state state; PHONGO_BSON_INIT_DEBUG_STATE(state); - php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state); + + if (!php_phongo_bson_to_zval_ex(bson_get_data(tags), tags->len, &state)) { + zval_ptr_dtor(&state.zchild); + return; + } + #if PHP_VERSION_ID >= 70000 ADD_ASSOC_ZVAL_EX(&retval, "tags", &state.zchild); #else diff --git a/src/MongoDB/Session.c b/src/MongoDB/Session.c index 8ed2b3216..36baa9969 100644 --- a/src/MongoDB/Session.c +++ b/src/MongoDB/Session.c @@ -560,7 +560,10 @@ static HashTable* php_phongo_session_get_debug_info(zval* object, int* is_temp T lsid = mongoc_client_session_get_lsid(intern->client_session); - php_phongo_bson_to_zval_ex(bson_get_data(lsid), lsid->len, &state); + if (!php_phongo_bson_to_zval_ex(bson_get_data(lsid), lsid->len, &state)) { + zval_ptr_dtor(&state.zchild); + goto done; + } #if PHP_VERSION_ID >= 70000 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 php_phongo_bson_state state; PHONGO_BSON_INIT_DEBUG_STATE(state); - php_phongo_bson_to_zval_ex(bson_get_data(cluster_time), cluster_time->len, &state); + + if (!php_phongo_bson_to_zval_ex(bson_get_data(cluster_time), cluster_time->len, &state)) { + zval_ptr_dtor(&state.zchild); + goto done; + } #if PHP_VERSION_ID >= 70000 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 ADD_ASSOC_NULL_EX(&retval, "server"); } +done: return Z_ARRVAL(retval); } /* }}} */ /* }}} */ diff --git a/src/MongoDB/WriteResult.c b/src/MongoDB/WriteResult.c index 1c47b47b2..82e6c6f41 100644 --- a/src/MongoDB/WriteResult.c +++ b/src/MongoDB/WriteResult.c @@ -425,7 +425,11 @@ static HashTable* php_phongo_writeresult_get_debug_info(zval* object, int* is_te PHONGO_BSON_INIT_DEBUG_STATE(state); bson_iter_array(&iter, &len, &data); - php_phongo_bson_to_zval_ex(data, len, &state); + if (!php_phongo_bson_to_zval_ex(data, len, &state)) { + zval_ptr_dtor(&state.zchild); + goto done; + } + #if PHP_VERSION_ID >= 70000 ADD_ASSOC_ZVAL_EX(&retval, "upsertedIds", &state.zchild); #else @@ -491,6 +495,7 @@ static HashTable* php_phongo_writeresult_get_debug_info(zval* object, int* is_te ADD_ASSOC_NULL_EX(&retval, "writeConcern"); } +done: return Z_ARRVAL(retval); } /* }}} */ /* }}} */