diff --git a/README.third_party.md b/README.third_party.md index 1c8129b08de..02eff8a7acf 100644 --- a/README.third_party.md +++ b/README.third_party.md @@ -50,7 +50,7 @@ a notice will be included in | [LibTomCrypt] | WTFPL, Public Domain | 1.18.2 | ✗ | ✗ | | [libunwind/libunwind] | MIT | v1.8.1 | | ✗ | | [linenoise] | BSD-2-Clause | Unknown | | ✗ | -| [MongoDB C Driver] | Apache-2.0 | 1.27.6 | ✗ | ✗ | +| [MongoDB C Driver] | Apache-2.0 | 1.28.1 | ✗ | ✗ | | [Mozilla Firefox] | MPL-2.0 | 128.8.0esr | unknown | ✗ | | [nlohmann-json] | MIT | 3.11.3 | ✗ | | | [nlohmann.json.decomposed] | MIT | 3.10.5 | unknown | | diff --git a/bazel/mongo_src_rules.bzl b/bazel/mongo_src_rules.bzl index 334893417c2..e2824ee58d5 100644 --- a/bazel/mongo_src_rules.bzl +++ b/bazel/mongo_src_rules.bzl @@ -1574,7 +1574,7 @@ def force_includes_hdr(package_name, name): return [] -# TODO(SERVER-102596): Stop including this flag when ASP is able to upgrade mongoc and mongocxx +# TODO(SERVER-103006): Stop including this flag when ASP is able to upgrade mongoc and mongocxx STREAMS_THIRD_PARTY_DIR = "src/mongo/db/modules/enterprise/src/streams/third_party" def package_specific_copt(package_name): diff --git a/sbom.json b/sbom.json index f65fb9c0a31..9c7afa81131 100644 --- a/sbom.json +++ b/sbom.json @@ -1191,7 +1191,7 @@ "name": "Organization: github" }, "name": "MongoDB C Driver", - "version": "1.27.6", + "version": "1.28.1", "licenses": [ { "license": { @@ -1199,7 +1199,7 @@ } } ], - "purl": "pkg:github/mongodb/mongo-c-driver@1.27.6", + "purl": "pkg:github/mongodb/mongo-c-driver@1.28.1", "properties": [ { "name": "internal:team_responsible", diff --git a/src/third_party/libbson/dist/src/common/common-b64-private.h b/src/third_party/libbson/dist/src/common/common-b64-private.h index 7f5c4e35d7d..4ef5fbd3db1 100644 --- a/src/third_party/libbson/dist/src/common/common-b64-private.h +++ b/src/third_party/libbson/dist/src/common/common-b64-private.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-present MongoDB Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/common/common-macros-private.h b/src/third_party/libbson/dist/src/common/common-macros-private.h index 360a0f51ead..e739710a430 100644 --- a/src/third_party/libbson/dist/src/common/common-macros-private.h +++ b/src/third_party/libbson/dist/src/common/common-macros-private.h @@ -1,3 +1,18 @@ +/* + * Copyright 2009-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "common-prelude.h" @@ -12,4 +27,32 @@ #define MONGOC_DEBUG_ASSERT(statement) ((void) 0) #endif +// `MC_ENABLE_CONVERSION_WARNING_BEGIN` enables -Wconversion to check for potentially unsafe integer conversions. +// The `bson_in_range_*` functions can help address these warnings by ensuring a cast is within bounds. +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) // gcc 4.6 added support for "diagnostic push". +#define MC_ENABLE_CONVERSION_WARNING_BEGIN \ + _Pragma ("GCC diagnostic push") _Pragma ("GCC diagnostic warning \"-Wconversion\"") +#define MC_ENABLE_CONVERSION_WARNING_END _Pragma ("GCC diagnostic pop") +#elif defined(__clang__) +#define MC_ENABLE_CONVERSION_WARNING_BEGIN \ + _Pragma ("clang diagnostic push") _Pragma ("clang diagnostic warning \"-Wconversion\"") +#define MC_ENABLE_CONVERSION_WARNING_END _Pragma ("clang diagnostic pop") +#else +#define MC_ENABLE_CONVERSION_WARNING_BEGIN +#define MC_ENABLE_CONVERSION_WARNING_END #endif + +// Disable the -Wcast-function-type-strict warning. +#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_BEGIN +#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_END +#if defined(__clang__) +#if __has_warning("-Wcast-function-type-strict") +#undef MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_BEGIN +#undef MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_END +#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_BEGIN \ + _Pragma ("clang diagnostic push") _Pragma ("clang diagnostic ignored \"-Wcast-function-type-strict\"") +#define MC_DISABLE_CAST_FUNCTION_TYPE_STRICT_WARNING_END _Pragma ("clang diagnostic pop") +#endif // __has_warning("-Wcast-function-type-strict") +#endif // defined(__clang__) + +#endif /* COMMON_MACROS_PRIVATE_H */ diff --git a/src/third_party/libbson/dist/src/common/common-md5-private.h b/src/third_party/libbson/dist/src/common/common-md5-private.h index 4feadb93154..a77d232df46 100644 --- a/src/third_party/libbson/dist/src/common/common-md5-private.h +++ b/src/third_party/libbson/dist/src/common/common-md5-private.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-present MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/common/common-prelude.h b/src/third_party/libbson/dist/src/common/common-prelude.h index 4f3a5fdd024..cc73b338d0b 100644 --- a/src/third_party/libbson/dist/src/common/common-prelude.h +++ b/src/third_party/libbson/dist/src/common/common-prelude.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-present MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/common/common-thread-private.h b/src/third_party/libbson/dist/src/common/common-thread-private.h index 291af21a90e..29ace085ddd 100644 --- a/src/third_party/libbson/dist/src/common/common-thread-private.h +++ b/src/third_party/libbson/dist/src/common/common-thread-private.h @@ -1,5 +1,5 @@ /* - * Copyright 2013-present MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/common/common-thread.c b/src/third_party/libbson/dist/src/common/common-thread.c index 9b26f6e9567..dbebd97727e 100644 --- a/src/third_party/libbson/dist/src/common/common-thread.c +++ b/src/third_party/libbson/dist/src/common/common-thread.c @@ -1,5 +1,5 @@ /* - * Copyright 2020-present MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ mcommon_thread_create (bson_thread_t *thread, BSON_THREAD_FUN_TYPE (func), void { BSON_ASSERT_PARAM (thread); BSON_ASSERT_PARAM (func); - BSON_ASSERT (arg || true); // optional. + BSON_OPTIONAL_PARAM (arg); // optional. return pthread_create (thread, NULL, func, arg); } int @@ -47,7 +47,7 @@ mcommon_thread_create (bson_thread_t *thread, BSON_THREAD_FUN_TYPE (func), void { BSON_ASSERT_PARAM (thread); BSON_ASSERT_PARAM (func); - BSON_ASSERT (arg || true); // optional. + BSON_OPTIONAL_PARAM (arg); // optional. *thread = (HANDLE) _beginthreadex (NULL, 0, func, arg, 0, NULL); if (0 == *thread) { diff --git a/src/third_party/libbson/dist/src/libbson/NEWS b/src/third_party/libbson/dist/src/libbson/NEWS index 7d21ef5f05b..c90b5738358 100644 --- a/src/third_party/libbson/dist/src/libbson/NEWS +++ b/src/third_party/libbson/dist/src/libbson/NEWS @@ -1,3 +1,33 @@ +libbson 1.28.1 +============== + +Fixes: + + * Fix large string handling in `bson_string_truncate`. + * Fix possible crash in `bson_value_copy`. + + +Thanks to everyone who contributed to the development of this release. + + * Joshua Siegel + * Kevin Albertson + + + +libbson 1.28.0 +============== + +New features: + + * Add `bson_validate_with_error_and_offset`. + +Build Configuration: + + * Remove automatic ccache detection and usage (CCache.cmake). + * Set [`CMAKE__COMPILER_LAUNCHER`](https://cmake.org/cmake/help/latest/envvar/CMAKE_LANG_COMPILER_LAUNCHER.html) to build with ccache. + * Remove `MONGO_USE_CCACHE` (no longer applicable; see above). + + libbson 1.27.6 ============== diff --git a/src/third_party/libbson/dist/src/libbson/libbson.rc.in b/src/third_party/libbson/dist/src/libbson/libbson.rc.in index 2ba98064c45..47afe6f140b 100644 --- a/src/third_party/libbson/dist/src/libbson/libbson.rc.in +++ b/src/third_party/libbson/dist/src/libbson/libbson.rc.in @@ -34,7 +34,7 @@ BEGIN VALUE "OriginalFilename", BSON_OUTPUT_BASENAME "-" BSON_API_VERSION ".dll" VALUE "ProductName", "MongoDB C Driver" VALUE "ProductVersion", BSON_VERSION_S - VALUE "LegalCopyright", "Copyright (C) 2013-present MongoDB, Inc." + VALUE "LegalCopyright", "Copyright 2009-present MongoDB, Inc." END END BLOCK "VarFileInfo" diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bcon.c b/src/third_party/libbson/dist/src/libbson/src/bson/bcon.c index 0779d89a96f..1835bd970b6 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bcon.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bcon.c @@ -3,7 +3,7 @@ * @brief BCON (BSON C Object Notation) Implementation */ -/* Copyright 2009-2013 MongoDB, Inc. +/* Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bcon.h b/src/third_party/libbson/dist/src/libbson/src/bson/bcon.h index d35365e6e6a..b067078ecdd 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bcon.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bcon.h @@ -5,7 +5,7 @@ #include -/* Copyright 2009-2013 MongoDB, Inc. +/* Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-atomic.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-atomic.c index 18dd4edb25e..64caa79bd45 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-atomic.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-atomic.c @@ -1,5 +1,5 @@ /* - * Copyright 2014 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-atomic.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-atomic.h index 60ab74c87ef..8195d8777f8 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-atomic.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-atomic.h @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -187,6 +187,7 @@ enum bson_memory_order { BSON_UNREACHABLE ("Invalid bson_memory_order value"); \ }) \ BSON_IF_GNU_LEGACY_ATOMICS ({ \ + BSON_UNUSED (order); \ __sync_synchronize (); \ return *a; \ }) \ @@ -213,7 +214,7 @@ enum bson_memory_order { default: \ BSON_UNREACHABLE ("Invalid bson_memory_order value"); \ }) \ - BSON_IF_GNU_LEGACY_ATOMICS (return __sync_val_compare_and_swap (a, *a, value);) \ + BSON_IF_GNU_LEGACY_ATOMICS (BSON_UNUSED (ord); return __sync_val_compare_and_swap (a, *a, value);) \ } \ \ static BSON_INLINE Type bson_atomic_##NamePart##_compare_exchange_strong ( \ diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-clock.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-clock.c index a9510c2e3b7..959cbe13322 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-clock.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-clock.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-clock.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-clock.h index a4845b7417d..4179152772a 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-clock.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-clock.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-cmp.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-cmp.h index 5a90d0f1a6e..f5785f52173 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-cmp.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-cmp.h @@ -1,5 +1,5 @@ /* - * Copyright 2022 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-compat.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-compat.h index f403fb4c77b..eb28dcd3eab 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-compat.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-compat.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,11 +36,11 @@ #ifdef BSON_OS_WIN32 -#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600) +#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0601) #undef _WIN32_WINNT #endif #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0600 +#define _WIN32_WINNT 0x0601 #endif #ifndef NOMINMAX #define NOMINMAX diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-config.h.in b/src/third_party/libbson/dist/src/libbson/src/bson/bson-config.h.in index 2849d0206a2..14254fba553 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-config.h.in +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-config.h.in @@ -1,5 +1,5 @@ /* - * Copyright 2018-present MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-context-private.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-context-private.h index 043497357b3..e260c55b17d 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-context-private.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-context-private.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-context.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-context.c index f9f545f77ea..6b8eb67ec05 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-context.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-context.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-context.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-context.h index 8399b57755b..882d080bbcb 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-context.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-context.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-decimal128.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-decimal128.c index 786963c24cf..b1ccec1841b 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-decimal128.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-decimal128.c @@ -1,6 +1,6 @@ /* - * Copyright 2015 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -269,7 +269,9 @@ bson_decimal128_to_string (const bson_decimal128_t *dec, /* IN */ } /* Exponent */ *(str_out++) = 'E'; - bson_snprintf (str_out, 6, "%+d", scientific_exponent); + // Truncation is OK. + int req = bson_snprintf (str_out, 6, "%+d", scientific_exponent); + BSON_ASSERT (req > 0); } else { /* Regular format with no decimal place */ if (exponent >= 0) { @@ -280,8 +282,11 @@ bson_decimal128_to_string (const bson_decimal128_t *dec, /* IN */ } else { int32_t radix_position = significand_digits + exponent; + // Reserve space for null terminator. + const int available_bytes = BSON_DECIMAL128_STRING - 1; + if (radix_position > 0) { /* non-zero digits before radix */ - for (int32_t i = 0; i < radix_position && (str_out - str) < BSON_DECIMAL128_STRING; i++) { + for (int32_t i = 0; i < radix_position && (str_out - str) < available_bytes; i++) { *(str_out++) = *(significand_read++) + '0'; } } else { /* leading zero before radix point */ @@ -294,7 +299,7 @@ bson_decimal128_to_string (const bson_decimal128_t *dec, /* IN */ } for (uint32_t i = 0; bson_cmp_greater_us (significand_digits - i, BSON_MAX (radix_position - 1, 0)) && - (str_out - str) < BSON_DECIMAL128_STRING; + (str_out - str) < available_bytes; i++) { *(str_out++) = *(significand_read++) + '0'; } diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-decimal128.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-decimal128.h index aa1d53afb0e..48d5f29ae98 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-decimal128.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-decimal128.h @@ -1,5 +1,5 @@ /* - * Copyright 2015 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-endian.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-endian.h index 1527f10887b..9b6cf9ef531 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-endian.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-endian.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,6 @@ #ifndef BSON_ENDIAN_H #define BSON_ENDIAN_H - -#if defined(__sun) -#include -#endif - #include #include #include @@ -36,12 +31,7 @@ BSON_BEGIN_DECLS #define BSON_BIG_ENDIAN 4321 #define BSON_LITTLE_ENDIAN 1234 - -#if defined(__sun) -#define BSON_UINT16_SWAP_LE_BE(v) BSWAP_16 ((uint16_t) v) -#define BSON_UINT32_SWAP_LE_BE(v) BSWAP_32 ((uint32_t) v) -#define BSON_UINT64_SWAP_LE_BE(v) BSWAP_64 ((uint64_t) v) -#elif defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__) && (__clang_major__ >= 3) && \ +#if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__) && (__clang_major__ >= 3) && \ (__clang_minor__ >= 1) #if __has_builtin(__builtin_bswap16) #define BSON_UINT16_SWAP_LE_BE(v) __builtin_bswap16 (v) diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-error.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-error.c index 0c6257b1e21..3a42e44af3e 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-error.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-error.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-error.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-error.h index 7d17b84cdcd..855af02bb19 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-error.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-error.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-iso8601-private.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-iso8601-private.h index 81909a79102..b4c846fff44 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-iso8601-private.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-iso8601-private.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-iso8601.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-iso8601.c index 47687cec24f..992ad91a455 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-iso8601.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-iso8601.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-iter.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-iter.c index 0925b02c184..5159a39b518 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-iter.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-iter.c @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,6 +62,7 @@ bson_iter_init (bson_iter_t *iter, /* OUT */ iter->d4 = 0; iter->next_off = 4; iter->err_off = 0; + iter->value = (bson_value_t){0}; return true; } @@ -640,7 +641,7 @@ fill_data_fields: /* subtype 2 has a redundant length header in the data */ memcpy (&binary_len, (iter->raw + iter->d3), sizeof (binary_len)); binary_len = BSON_UINT32_FROM_LE (binary_len); - if (binary_len + 4 != l) { + if (binary_len != l - 4) { iter->err_off = iter->d3; goto mark_invalid; } diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-iter.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-iter.h index 5370922d6d6..56bda8e8644 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-iter.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-iter.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-json-private.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-json-private.h index 7a562a2b093..7537d6fc453 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-json-private.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-json-private.h @@ -1,5 +1,5 @@ /* - * Copyright 2020 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-json.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-json.c index 7d96104fe1d..5b53dd86a32 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-json.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-json.c @@ -1,5 +1,5 @@ /* - * Copyright 2014 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-json.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-json.h index 57f14a71969..68fbcb8ae96 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-json.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-json.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-keys.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-keys.c index 9ba141c6ce4..7307664ce64 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-keys.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-keys.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ #include #include +#include static const char *gUint32Strs[] = { @@ -141,5 +142,9 @@ bson_uint32_to_string (uint32_t value, /* IN */ *strptr = str; - return bson_snprintf (str, size, "%u", value); + int ret = bson_snprintf (str, size, "%u", value); + // Truncation is OK. + BSON_ASSERT (ret > 0); + BSON_ASSERT (bson_in_range_size_t_signed (ret)); + return (size_t) ret; } diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-keys.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-keys.h index 14f19f321b2..08f14e8ba38 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-keys.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-keys.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-macros.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-macros.h index f9263914f1f..86c399db235 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-macros.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-macros.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -232,6 +232,10 @@ } \ } while (0) +// `BSON_OPTIONAL_PARAM` is a documentation-only macro to document X may be NULL. +// Useful in combination with `BSON_ASSERT_PARAM` to document and assert pointer parameters. +#define BSON_OPTIONAL_PARAM(param) (void) 0 + /* obsolete macros, preserved for compatibility */ #define BSON_STATIC_ASSERT(s) BSON_STATIC_ASSERT_ (s, __LINE__) #define BSON_STATIC_ASSERT_JOIN(a, b) BSON_STATIC_ASSERT_JOIN2 (a, b) diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-memory.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-memory.c index 6c37003f2be..fbf7fbd2e60 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-memory.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-memory.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-memory.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-memory.h index bde15edaef8..113b9ea14f2 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-memory.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-memory.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-oid.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-oid.c index 090ac3eda8b..ae7d8910624 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-oid.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-oid.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-oid.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-oid.h index 4829e28f5e4..d7d1585f9fc 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-oid.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-oid.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-prelude.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-prelude.h index 2469125fe17..adbbf14c592 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-prelude.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-prelude.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-present MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-private.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-private.h index 3b006a34796..92004805767 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-private.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-private.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-reader.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-reader.c index 84ade059116..1d3feb7d9c4 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-reader.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-reader.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-reader.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-reader.h index 827b0fe936b..3de90406650 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-reader.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-reader.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-string.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-string.c index 85de12cb781..0ca48b70086 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-string.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-string.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -292,7 +292,7 @@ bson_string_append_printf (bson_string_t *string, const char *format, ...) * Truncate the string @string to @len bytes. * * The underlying memory will be released via realloc() down to - * the minimum required size specified by @len. + * the minimum required size (at power-of-two boundary) specified by @len. * * Returns: * None. @@ -307,19 +307,17 @@ void bson_string_truncate (bson_string_t *string, /* IN */ uint32_t len) /* IN */ { - uint32_t alloc; - - BSON_ASSERT (string); - BSON_ASSERT (len < INT_MAX); - - alloc = len + 1; - - if (alloc < 16) { - alloc = 16; + BSON_ASSERT_PARAM (string); + if (len == string->len) { + return; } - - if (!bson_is_power_of_two (alloc)) { - alloc = (uint32_t) bson_next_power_of_two ((size_t) alloc); + uint32_t needed = len; + BSON_ASSERT (needed < UINT32_MAX); + needed += 1u; // Add one for trailing NULL byte. + uint32_t alloc = bson_next_power_of_two_u32 (needed); + if (alloc == 0) { + // Overflowed: saturate at UINT32_MAX. + alloc = UINT32_MAX; } string->str = bson_realloc (string->str, alloc); diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-string.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-string.h index 3759afff0bd..4146ebaa2bf 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-string.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-string.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-timegm-private.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-timegm-private.h index 93d9a8e7216..0490d012a83 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-timegm-private.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-timegm-private.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-types.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-types.h index 31486687396..135b60f833f 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-types.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-types.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-utf8.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-utf8.c index 61fa98598ed..b39da8f5448 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-utf8.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-utf8.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -278,6 +278,15 @@ bson_utf8_escape_for_json (const char *utf8, /* IN */ end = utf8 + utf8_len; while (utf8 < end) { + uint8_t mask; + uint8_t length_of_char; + + // Check if expected char length goes past end + _bson_utf8_get_sequence (utf8, &length_of_char, &mask); + if (utf8 > end - length_of_char) { + goto invalid_utf8; + } + c = bson_utf8_get_char (utf8); switch (c) { @@ -313,18 +322,25 @@ bson_utf8_escape_for_json (const char *utf8, /* IN */ if (c) { utf8 = bson_utf8_next_char (utf8); } else { - if (length_provided && !*utf8) { - /* we escaped nil as '\u0000', now advance past it */ - utf8++; + if (length_provided) { + // Check if current character is null character, + // if so skip past it as we've already added '\\u0000' above + if (*utf8 == '\0' || (*utf8 == '\xc0' && *(utf8 + 1) == '\x80')) { + utf8 += (*utf8 == '\0') ? 1 : 2; + } else { + goto invalid_utf8; + } } else { - /* invalid UTF-8 */ - bson_string_free (str, true); - return NULL; + goto invalid_utf8; } } } return bson_string_free (str, false); + +invalid_utf8: + bson_string_free (str, true); + return NULL; } diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-utf8.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-utf8.h index af085969412..fc58d3c5a72 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-utf8.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-utf8.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-value.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-value.c index 3e3c46890db..a8aabd3344b 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-value.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-value.c @@ -1,5 +1,5 @@ /* - * Copyright 2014 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ #include #include #include +#include void @@ -35,8 +36,11 @@ bson_value_copy (const bson_value_t *src, /* IN */ dst->value.v_double = src->value.v_double; break; case BSON_TYPE_UTF8: + BSON_ASSERT (bson_in_range_size_t_unsigned (src->value.v_utf8.len)); + size_t utf8_len_sz = (size_t) src->value.v_utf8.len; + BSON_ASSERT (utf8_len_sz <= SIZE_MAX - 1); dst->value.v_utf8.len = src->value.v_utf8.len; - dst->value.v_utf8.str = bson_malloc (src->value.v_utf8.len + 1); + dst->value.v_utf8.str = bson_malloc (utf8_len_sz + 1); memcpy (dst->value.v_utf8.str, src->value.v_utf8.str, dst->value.v_utf8.len); dst->value.v_utf8.str[dst->value.v_utf8.len] = '\0'; break; @@ -68,28 +72,40 @@ bson_value_copy (const bson_value_t *src, /* IN */ dst->value.v_regex.options = bson_strdup (src->value.v_regex.options); break; case BSON_TYPE_DBPOINTER: + BSON_ASSERT (bson_in_range_size_t_unsigned (src->value.v_dbpointer.collection_len)); + size_t dbpointer_len_sz = (size_t) src->value.v_dbpointer.collection_len; + BSON_ASSERT (dbpointer_len_sz <= SIZE_MAX - 1); dst->value.v_dbpointer.collection_len = src->value.v_dbpointer.collection_len; - dst->value.v_dbpointer.collection = bson_malloc (src->value.v_dbpointer.collection_len + 1); + dst->value.v_dbpointer.collection = bson_malloc (dbpointer_len_sz + 1); memcpy ( dst->value.v_dbpointer.collection, src->value.v_dbpointer.collection, dst->value.v_dbpointer.collection_len); dst->value.v_dbpointer.collection[dst->value.v_dbpointer.collection_len] = '\0'; bson_oid_copy (&src->value.v_dbpointer.oid, &dst->value.v_dbpointer.oid); break; case BSON_TYPE_CODE: + BSON_ASSERT (bson_in_range_size_t_unsigned (src->value.v_code.code_len)); + size_t code_len_sz = (size_t) src->value.v_code.code_len; + BSON_ASSERT (code_len_sz <= SIZE_MAX - 1); dst->value.v_code.code_len = src->value.v_code.code_len; - dst->value.v_code.code = bson_malloc (src->value.v_code.code_len + 1); + dst->value.v_code.code = bson_malloc (code_len_sz + 1); memcpy (dst->value.v_code.code, src->value.v_code.code, dst->value.v_code.code_len); dst->value.v_code.code[dst->value.v_code.code_len] = '\0'; break; case BSON_TYPE_SYMBOL: + BSON_ASSERT (bson_in_range_size_t_unsigned (src->value.v_symbol.len)); + size_t symbol_len_sz = (size_t) src->value.v_symbol.len; + BSON_ASSERT (symbol_len_sz <= SIZE_MAX - 1); dst->value.v_symbol.len = src->value.v_symbol.len; - dst->value.v_symbol.symbol = bson_malloc (src->value.v_symbol.len + 1); + dst->value.v_symbol.symbol = bson_malloc (symbol_len_sz + 1); memcpy (dst->value.v_symbol.symbol, src->value.v_symbol.symbol, dst->value.v_symbol.len); dst->value.v_symbol.symbol[dst->value.v_symbol.len] = '\0'; break; case BSON_TYPE_CODEWSCOPE: + BSON_ASSERT (bson_in_range_size_t_unsigned (src->value.v_codewscope.code_len)); + size_t codewscope_len_sz = (size_t) src->value.v_codewscope.code_len; + BSON_ASSERT (codewscope_len_sz <= SIZE_MAX - 1); dst->value.v_codewscope.code_len = src->value.v_codewscope.code_len; - dst->value.v_codewscope.code = bson_malloc (src->value.v_codewscope.code_len + 1); + dst->value.v_codewscope.code = bson_malloc (codewscope_len_sz + 1); memcpy (dst->value.v_codewscope.code, src->value.v_codewscope.code, dst->value.v_codewscope.code_len); dst->value.v_codewscope.code[dst->value.v_codewscope.code_len] = '\0'; dst->value.v_codewscope.scope_len = src->value.v_codewscope.scope_len; diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-value.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-value.h index 41756907df0..afb11a5006b 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-value.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-value.h @@ -1,5 +1,5 @@ /* - * Copyright 2014 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-version-functions.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-version-functions.c index 90406edb366..55de41026c9 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-version-functions.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-version-functions.c @@ -1,5 +1,5 @@ /* - * Copyright 2015 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-version-functions.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-version-functions.h index 923dcf0dc60..e97376a57d2 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-version-functions.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-version-functions.h @@ -1,5 +1,5 @@ /* - * Copyright 2015 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-version.h.in b/src/third_party/libbson/dist/src/libbson/src/bson/bson-version.h.in index 618369995dc..4d9fcac4893 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-version.h.in +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-version.h.in @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-writer.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson-writer.c index d547698aea5..40721eb5498 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-writer.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-writer.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson-writer.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson-writer.h index dd7d8988c9c..37e8c26c16d 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson-writer.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson-writer.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson.c b/src/third_party/libbson/dist/src/libbson/src/bson/bson.c index e29b2a771cc..5b91bec86af 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson.c +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson.c @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -3299,29 +3299,35 @@ _bson_validate_internal (const bson_t *bson, bson_validate_state_t *state) bool bson_validate (const bson_t *bson, bson_validate_flags_t flags, size_t *offset) { - bson_validate_state_t state; - - state.flags = flags; - _bson_validate_internal (bson, &state); - - if (state.err_offset > 0 && offset) { - *offset = (size_t) state.err_offset; - } - - return state.err_offset < 0; + return bson_validate_with_error_and_offset (bson, flags, offset, NULL); } bool bson_validate_with_error (const bson_t *bson, bson_validate_flags_t flags, bson_error_t *error) +{ + return bson_validate_with_error_and_offset (bson, flags, NULL, error); +} + + +bool +bson_validate_with_error_and_offset (const bson_t *bson, + bson_validate_flags_t flags, + size_t *offset, + bson_error_t *error) { bson_validate_state_t state; state.flags = flags; _bson_validate_internal (bson, &state); - if (state.err_offset > 0 && error) { - memcpy (error, &state.error, sizeof *error); + if (state.err_offset > 0) { + if (offset) { + *offset = (size_t) state.err_offset; + } + if (error) { + memcpy (error, &state.error, sizeof *error); + } } return state.err_offset < 0; diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/bson.h b/src/third_party/libbson/dist/src/libbson/src/bson/bson.h index f86967bae1f..f66b5a1297c 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/bson.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/bson.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -454,6 +454,25 @@ BSON_EXPORT (bool) bson_validate_with_error (const bson_t *bson, bson_validate_flags_t flags, bson_error_t *error); +/** + * bson_validate_with_error_and_offset: + * @bson: A bson_t. + * @offset: A location for the error offset. + * @error: A location for the error info. + * + * Validates a BSON document by walking through the document and inspecting + * the fields for valid content. + * + * Returns: true if @bson is valid; otherwise false, @offset is set + * and @error is filled out. + */ +BSON_EXPORT (bool) +bson_validate_with_error_and_offset (const bson_t *bson, + bson_validate_flags_t flags, + size_t *offset, + bson_error_t *error); + + /** * bson_as_json_with_opts: * @bson: A bson_t. diff --git a/src/third_party/libbson/dist/src/libbson/src/bson/forwarding/bson.h b/src/third_party/libbson/dist/src/libbson/src/bson/forwarding/bson.h index cfe6d0682f3..e8ae7264a03 100644 --- a/src/third_party/libbson/dist/src/libbson/src/bson/forwarding/bson.h +++ b/src/third_party/libbson/dist/src/libbson/src/bson/forwarding/bson.h @@ -1,5 +1,5 @@ /* - * Copyright 2018-present MongoDB, Inc. + * Copyright 2009-present MongoDB, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,4 +15,4 @@ */ /* Including bson.h is superseded. Use bson/bson.h instead. */ -#include "bson/bson.h" \ No newline at end of file +#include "bson/bson.h" diff --git a/src/third_party/libbson/import.sh b/src/third_party/libbson/import.sh index d48aa0c5e9e..1bbea64a2c7 100755 --- a/src/third_party/libbson/import.sh +++ b/src/third_party/libbson/import.sh @@ -18,7 +18,7 @@ if grep -q Microsoft /proc/version; then fi NAME=libbson -VERSION=1.27.6 +VERSION=1.28.1 if grep -q Microsoft /proc/version; then SRC_ROOT=$(wslpath -u $(powershell.exe -Command "Get-ChildItem Env:TEMP | Get-Content | Write-Host"))