Skip to content

Commit 54ddb8b

Browse files
committed
Merge remote-tracking branch 'upstream/master' into DRIVERS-3546
2 parents 4238a0d + 92b5144 commit 54ddb8b

5 files changed

Lines changed: 114 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# ChangeLog
22

3-
## Unreleased
3+
## 1.20.0 [Unreleased]
4+
5+
<!-- TODO: add entries for next release -->
6+
7+
## 1.19.0
48

59
### Added
610
- Stable support for prefix and suffix queries:
@@ -11,7 +15,12 @@
1115
### Removed
1216
- Support for the experimental `prefixPreview` and `suffixPreview` query types.
1317

14-
<!-- TODO: add entries for next release -->
18+
19+
## 1.18.2
20+
21+
### Fixed
22+
- Add musl arm64 release to GitHub release. This was an omission in 1.18.0.
23+
- Reject large KMS replies.
1524

1625
## 1.18.1
1726

bindings/python/pymongocrypt/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "1.18.1"
15+
__version__ = "1.18.2.dev0"
1616

1717
_MIN_LIBMONGOCRYPT_VERSION = "1.8.0"

etc/cyclonedx.sbom.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
}
5858
],
5959
"metadata": {
60-
"timestamp": "2026-05-01T14:49:06.464175+00:00",
60+
"timestamp": "2026-06-05T18:21:36.076717+00:00",
6161
"tools": [
6262
{
6363
"externalReferences": [
@@ -100,7 +100,7 @@
100100
}
101101
]
102102
},
103-
"serialNumber": "urn:uuid:5c89265b-cc3d-4649-878b-17b482325b56",
103+
"serialNumber": "urn:uuid:30a59905-5ec6-4cb7-b14d-51382db97651",
104104
"version": 1,
105105
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
106106
"bomFormat": "CycloneDX",

kms-message/src/kms_kmip_response_parser.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ kms_kmip_response_parser_feed (kms_kmip_response_parser_t *parser,
111111
uint32_t temp;
112112
memcpy (&temp, parser->buf->str + FIRST_LENGTH_OFFSET, sizeof (uint32_t));
113113
parser->first_len = KMS_UINT32_FROM_BE (temp);
114+
if (parser->first_len > KMS_PARSER_MAX_RESPONSE_LEN) {
115+
KMS_ERROR (parser, "KMS KMIP response too large");
116+
return false;
117+
}
114118
}
115119
return true;
116120
}

test/test-mongocrypt-kms-ctx.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "mongocrypt-key-private.h"
2121
#include "mongocrypt-kms-ctx-private.h"
2222
#include "mongocrypt-private.h"
23+
#include "test-mongocrypt-assert.h"
2324
#include "test-mongocrypt-util.h"
2425
#include "test-mongocrypt.h"
2526

@@ -885,6 +886,100 @@ static void _test_mongocrypt_kms_ctx_feed_empty_bytes(_mongocrypt_tester_t *test
885886
mongocrypt_status_destroy(status);
886887
}
887888

889+
// _test_mongocrypt_kms_ctx_kmip_response_bad_length tests KMIP responses that report bad lengths.
890+
static void _test_mongocrypt_kms_ctx_kmip_response_bad_length(_mongocrypt_tester_t *tester) {
891+
mongocrypt_t *crypt = _mongocrypt_tester_mongocrypt(TESTER_MONGOCRYPT_DEFAULT);
892+
bool ok;
893+
uint8_t secretdata[KMS_KMIP_REQUEST_SECRETDATA_LENGTH] = {0};
894+
mongocrypt_status_t *status = mongocrypt_status_new();
895+
_mongocrypt_endpoint_t *endpoint = _mongocrypt_endpoint_new("example.com", -1, NULL /* opts */, status);
896+
ASSERT_OK_STATUS(endpoint != NULL, status);
897+
898+
// Regression test for MONGOCRYPT-909: test UINT32_MAX
899+
{
900+
mongocrypt_kms_ctx_t kms_ctx = {0};
901+
static const char *kmip_header = "\x42\x00\x7b\x01" // Tag=ResponseMessage, Type=Structure
902+
"\xff\xff\xff\xff"; // Length = UINT32_MAX
903+
904+
ok = _mongocrypt_kms_ctx_init_kmip_register(&kms_ctx,
905+
endpoint,
906+
secretdata,
907+
KMS_KMIP_REQUEST_SECRETDATA_LENGTH,
908+
"kmip",
909+
&crypt->log);
910+
ASSERT_OK_STATUS(ok, kms_ctx.status);
911+
912+
// Parser requests 8 bytes for initial header:
913+
ASSERT_CMPINT(mongocrypt_kms_ctx_bytes_needed(&kms_ctx), ==, 8u);
914+
915+
mongocrypt_binary_t *bytes = mongocrypt_binary_new_from_data((uint8_t *)kmip_header, 8u);
916+
917+
// Expect error (not abort):
918+
ASSERT_FAILS(mongocrypt_kms_ctx_feed(&kms_ctx, bytes), &kms_ctx, "KMS KMIP response too large");
919+
920+
mongocrypt_binary_destroy(bytes);
921+
_mongocrypt_kms_ctx_cleanup(&kms_ctx);
922+
}
923+
924+
// Length reported is less than data fed.
925+
{
926+
mongocrypt_kms_ctx_t kms_ctx = {0};
927+
static const char *kmip_header = "\x42\x00\x7b\x01" // Tag=ResponseMessage, Type=Structure
928+
"\x00\x00\x00\x01"; // Length = 1
929+
ASSERT_OK_STATUS(endpoint != NULL, status);
930+
931+
ok = _mongocrypt_kms_ctx_init_kmip_register(&kms_ctx,
932+
endpoint,
933+
secretdata,
934+
KMS_KMIP_REQUEST_SECRETDATA_LENGTH,
935+
"kmip",
936+
&crypt->log);
937+
ASSERT_OK_STATUS(ok, kms_ctx.status);
938+
939+
// Parser requests 8 bytes for initial header:
940+
ASSERT_CMPINT(mongocrypt_kms_ctx_bytes_needed(&kms_ctx), ==, 8u);
941+
942+
mongocrypt_binary_t *bytes = mongocrypt_binary_new_from_data((uint8_t *)kmip_header, 8u);
943+
ASSERT_OK(mongocrypt_kms_ctx_feed(&kms_ctx, bytes), &kms_ctx);
944+
945+
ASSERT_CMPINT(mongocrypt_kms_ctx_bytes_needed(&kms_ctx), ==, 1u);
946+
// Attempting to feed more data errors.
947+
ASSERT_FAILS(mongocrypt_kms_ctx_feed(&kms_ctx, bytes), &kms_ctx, "KMS response fed too much data");
948+
949+
mongocrypt_binary_destroy(bytes);
950+
_mongocrypt_kms_ctx_cleanup(&kms_ctx);
951+
}
952+
953+
// Length reported is zero.
954+
{
955+
mongocrypt_kms_ctx_t kms_ctx = {0};
956+
static const char *kmip_header = "\x42\x00\x7b\x01" // Tag=ResponseMessage, Type=Structure
957+
"\x00\x00\x00\x00"; // Length = 0
958+
ASSERT_OK_STATUS(endpoint != NULL, status);
959+
960+
ok = _mongocrypt_kms_ctx_init_kmip_register(&kms_ctx,
961+
endpoint,
962+
secretdata,
963+
KMS_KMIP_REQUEST_SECRETDATA_LENGTH,
964+
"kmip",
965+
&crypt->log);
966+
ASSERT_OK_STATUS(ok, kms_ctx.status);
967+
968+
// Parser requests 8 bytes for initial header:
969+
ASSERT_CMPINT(mongocrypt_kms_ctx_bytes_needed(&kms_ctx), ==, 8u);
970+
971+
mongocrypt_binary_t *bytes = mongocrypt_binary_new_from_data((uint8_t *)kmip_header, 8u);
972+
ASSERT_FAILS(mongocrypt_kms_ctx_feed(&kms_ctx, bytes), &kms_ctx, "Error getting UniqueIdentifer");
973+
974+
mongocrypt_binary_destroy(bytes);
975+
_mongocrypt_kms_ctx_cleanup(&kms_ctx);
976+
}
977+
978+
_mongocrypt_endpoint_destroy(endpoint);
979+
mongocrypt_status_destroy(status);
980+
mongocrypt_destroy(crypt);
981+
}
982+
888983
void _mongocrypt_tester_install_kms_ctx(_mongocrypt_tester_t *tester) {
889984
INSTALL_TEST(_test_mongocrypt_kms_ctx_kmip_register);
890985
INSTALL_TEST(_test_mongocrypt_kms_ctx_kmip_activate);
@@ -895,4 +990,5 @@ void _mongocrypt_tester_install_kms_ctx(_mongocrypt_tester_t *tester) {
895990
INSTALL_TEST(_test_mongocrypt_kms_ctx_get_kms_provider);
896991
INSTALL_TEST(_test_mongocrypt_kms_ctx_default_port);
897992
INSTALL_TEST(_test_mongocrypt_kms_ctx_feed_empty_bytes);
993+
INSTALL_TEST(_test_mongocrypt_kms_ctx_kmip_response_bad_length);
898994
}

0 commit comments

Comments
 (0)