Skip to content

PHPC-990: Strict type validation for boolean URI options #1713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ UPGRADE FROM 1.x to 2.0
`allowPartialResults` instead), `maxScan`, `modifiers` (use alternative
top-level options instead), `oplogReplay`, and `snapshot`. Support for
negative `limit` values has been removed (use `singleBatch` instead).
* The `MongoDB\Driver\Manager` constructor now throws if the URI options array
includes a non-boolean value for an option expecting a boolean. This behavior
is now consistent with validation for other option types.
14 changes: 10 additions & 4 deletions src/phongo_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,23 @@ static bool php_phongo_apply_options_to_uri(mongoc_uri_t* uri, bson_t* options)
}

if (mongoc_uri_option_is_bool(key)) {
/* The option's type is not validated because bson_iter_as_bool() is
* used to cast the value to a boolean. Validation may be introduced
* in PHPC-990. */
if (!mongoc_uri_set_option_as_bool(uri, key, bson_iter_as_bool(&iter))) {
if (!BSON_ITER_HOLDS_BOOL(&iter)) {
PHONGO_URI_INVALID_TYPE(iter, "boolean");
return false;
}

if (!mongoc_uri_set_option_as_bool(uri, key, bson_iter_bool(&iter))) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Failed to parse \"%s\" URI option", key);
return false;
}

continue;
}

/* Note: mongoc_uri_option_is_int32 also accepts int64 options, but
* BSON_ITER_HOLDS_INT32 would reject a 64-bit value. This is not a
* problem as MONGOC_URI_WTIMEOUTMS is the only 64-bit option and it is
* handled explicitly in php_phongo_apply_wc_options_to_uri. */
if (mongoc_uri_option_is_int32(key)) {
if (!BSON_ITER_HOLDS_INT32(&iter)) {
PHONGO_URI_INVALID_TYPE(iter, "32-bit integer");
Expand Down
Loading