Skip to content

Commit 505bfca

Browse files
authored
CDRIVER-3931 Check for null document in bson parser parse (#760)
1 parent ab48926 commit 505bfca

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/libmongoc/tests/bsonutil/bson-parser.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -638,30 +638,33 @@ bson_parser_parse (bson_parser_t *parser, bson_t *in, bson_error_t *error)
638638
bson_iter_t iter;
639639
bson_parser_entry_t *entry = NULL;
640640

641-
BSON_FOREACH (in, iter)
642-
{
643-
const char *key = bson_iter_key (&iter);
644-
bson_parser_entry_t *matched = NULL;
645-
/* Check for a corresponding entry. */
646-
LL_FOREACH (parser->entries, entry)
641+
/* Check that document is not null. */
642+
if (in) {
643+
BSON_FOREACH (in, iter)
647644
{
648-
if (0 == strcmp (entry->key, key)) {
649-
matched = entry;
650-
break;
645+
const char *key = bson_iter_key (&iter);
646+
bson_parser_entry_t *matched = NULL;
647+
/* Check for a corresponding entry. */
648+
LL_FOREACH (parser->entries, entry)
649+
{
650+
if (0 == strcmp (entry->key, key)) {
651+
matched = entry;
652+
break;
653+
}
651654
}
652-
}
653655

654-
if (matched) {
655-
if (!entry_marshal (entry, &iter, error)) {
656+
if (matched) {
657+
if (!entry_marshal (entry, &iter, error)) {
658+
return false;
659+
}
660+
entry->set = true;
661+
} else if (parser->allow_extra) {
662+
BSON_APPEND_VALUE (parser->extra, key, bson_iter_value (&iter));
663+
} else {
664+
test_set_error (
665+
error, "Extra field '%s' found parsing: %s", key, tmp_json (in));
656666
return false;
657667
}
658-
entry->set = true;
659-
} else if (parser->allow_extra) {
660-
BSON_APPEND_VALUE (parser->extra, key, bson_iter_value (&iter));
661-
} else {
662-
test_set_error (
663-
error, "Extra field '%s' found parsing: %s", key, tmp_json (in));
664-
return false;
665668
}
666669
}
667670

0 commit comments

Comments
 (0)