Skip to content

Commit 0d9a4d9

Browse files
Scott Gayouajdavis
Scott Gayou
authored andcommitted
Fix for CVE-2018-16790 -- Verify bounds before binary length read.
As reported here: https://jira.mongodb.org/browse/CDRIVER-2819, a heap overread occurs due a failure to correctly verify data bounds. In the original check, len - o returns the data left including the sizeof(l) we just read. Instead, the comparison should check against the data left NOT including the binary int32, i.e. just subtype (byte*) instead of int32 subtype (byte*). Added in test for corrupted BSON example.
1 parent 47d0f7e commit 0d9a4d9

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ _bson_iter_next_internal (bson_iter_t *iter, /* INOUT */
618618
memcpy (&l, iter->raw + iter->d1, sizeof (l));
619619
l = BSON_UINT32_FROM_LE (l);
620620

621-
if (l >= (len - o)) {
621+
if (l >= (len - o - 4)) {
622622
iter->err_off = o;
623623
goto mark_invalid;
624624
}

src/libbson/tests/binary/test59.bson

17 Bytes
Binary file not shown.

src/libbson/tests/test-bson.c

+5
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,11 @@ test_bson_validate (void)
12491249
12,
12501250
BSON_VALIDATE_NONE,
12511251
"corrupt BSON");
1252+
VALIDATE_TEST ("test59.bson",
1253+
BSON_VALIDATE_NONE,
1254+
9,
1255+
BSON_VALIDATE_NONE,
1256+
"corrupt BSON");
12521257

12531258
/* DBRef validation */
12541259
b = BCON_NEW ("my_dbref",

0 commit comments

Comments
 (0)