Skip to content

CDRIVER-3931 Check for null document in bson parser parse #760

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 1 commit into from
Mar 17, 2021
Merged
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
41 changes: 22 additions & 19 deletions src/libmongoc/tests/bsonutil/bson-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,30 +638,33 @@ bson_parser_parse (bson_parser_t *parser, bson_t *in, bson_error_t *error)
bson_iter_t iter;
bson_parser_entry_t *entry = NULL;

BSON_FOREACH (in, iter)
{
const char *key = bson_iter_key (&iter);
bson_parser_entry_t *matched = NULL;
/* Check for a corresponding entry. */
LL_FOREACH (parser->entries, entry)
/* Check that document is not null. */
if (in) {
BSON_FOREACH (in, iter)
{
if (0 == strcmp (entry->key, key)) {
matched = entry;
break;
const char *key = bson_iter_key (&iter);
bson_parser_entry_t *matched = NULL;
/* Check for a corresponding entry. */
LL_FOREACH (parser->entries, entry)
{
if (0 == strcmp (entry->key, key)) {
matched = entry;
break;
}
}
}

if (matched) {
if (!entry_marshal (entry, &iter, error)) {
if (matched) {
if (!entry_marshal (entry, &iter, error)) {
return false;
}
entry->set = true;
} else if (parser->allow_extra) {
BSON_APPEND_VALUE (parser->extra, key, bson_iter_value (&iter));
} else {
test_set_error (
error, "Extra field '%s' found parsing: %s", key, tmp_json (in));
return false;
}
entry->set = true;
} else if (parser->allow_extra) {
BSON_APPEND_VALUE (parser->extra, key, bson_iter_value (&iter));
} else {
test_set_error (
error, "Extra field '%s' found parsing: %s", key, tmp_json (in));
return false;
}
}

Expand Down