Skip to content

Commit ad8e82b

Browse files
Roman-KoshelevkevinAlbs
authored andcommitted
CDRIVER-5575 error on failure to init subdocument
Propagate error in `bson_iter_visit_all` when initializing subdocument with `bson_init_static` fails.
1 parent c179563 commit ad8e82b

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/libbson/src/bson/bson-iter.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,11 @@ bson_iter_visit_all (bson_iter_t *iter, /* INOUT */
19441944

19451945
bson_iter_document (iter, &doclen, &docbuf);
19461946

1947-
if (bson_init_static (&b, docbuf, doclen) && VISIT_DOCUMENT (iter, key, &b, data)) {
1947+
if (!bson_init_static (&b, docbuf, doclen)) {
1948+
iter->err_off = iter->off;
1949+
break;
1950+
}
1951+
if (VISIT_DOCUMENT (iter, key, &b, data)) {
19481952
return true;
19491953
}
19501954
} break;
@@ -1955,7 +1959,11 @@ bson_iter_visit_all (bson_iter_t *iter, /* INOUT */
19551959

19561960
bson_iter_array (iter, &doclen, &docbuf);
19571961

1958-
if (bson_init_static (&b, docbuf, doclen) && VISIT_ARRAY (iter, key, &b, data)) {
1962+
if (!bson_init_static (&b, docbuf, doclen)) {
1963+
iter->err_off = iter->off;
1964+
break;
1965+
}
1966+
if (VISIT_ARRAY (iter, key, &b, data)) {
19591967
return true;
19601968
}
19611969
} break;
@@ -2079,7 +2087,11 @@ bson_iter_visit_all (bson_iter_t *iter, /* INOUT */
20792087
return true;
20802088
}
20812089

2082-
if (bson_init_static (&b, docbuf, doclen) && VISIT_CODEWSCOPE (iter, key, length, code, &b, data)) {
2090+
if (!bson_init_static (&b, docbuf, doclen)) {
2091+
iter->err_off = iter->off;
2092+
break;
2093+
}
2094+
if (VISIT_CODEWSCOPE (iter, key, length, code, &b, data)) {
20832095
return true;
20842096
}
20852097
} break;

src/libbson/tests/binary/test60.bson

15 Bytes
Binary file not shown.

src/libbson/tests/test-bson.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,7 @@ test_bson_validate (void)
11851185
VALIDATE_TEST ("test53.bson", BSON_VALIDATE_NONE, 6, BSON_VALIDATE_NONE, "corrupt BSON");
11861186
VALIDATE_TEST ("test54.bson", BSON_VALIDATE_NONE, 12, BSON_VALIDATE_NONE, "corrupt BSON");
11871187
VALIDATE_TEST ("test59.bson", BSON_VALIDATE_NONE, 9, BSON_VALIDATE_NONE, "corrupt BSON");
1188+
VALIDATE_TEST ("test60.bson", BSON_VALIDATE_NONE, 4, BSON_VALIDATE_NONE, "corrupt BSON");
11881189

11891190
/* DBRef validation */
11901191
b = BCON_NEW ("my_dbref", "{", "$ref", BCON_UTF8 ("collection"), "$id", BCON_INT32 (1), "}");

0 commit comments

Comments
 (0)