Skip to content

Commit 5acf2a7

Browse files
kevinAlbsmdb-ad
authored andcommitted
MONGOCRYPT-807 Add missing error state transition (#1010)
* add missing `_mongocrypt_ctx_fail` in `FLE2RangeFindDriverSpec_to_ciphertexts`
1 parent db1b417 commit 5acf2a7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/mongocrypt-ctx-encrypt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ static bool FLE2RangeFindDriverSpec_to_ciphertexts(mongocrypt_ctx_t *ctx, mongoc
12591259
&iter,
12601260
&with_ciphertexts,
12611261
ctx->status)) {
1262+
_mongocrypt_ctx_fail(ctx);
12621263
goto fail;
12631264
}
12641265
}

test/test-mongocrypt-ctx-encrypt.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,7 @@ static void ee_testcase_run(ee_testcase *tc) {
19881988
bool ret = mongocrypt_ctx_finalize(ctx, got);
19891989
if (tc->expect_finalize_error) {
19901990
ASSERT_FAILS(ret, ctx, tc->expect_finalize_error);
1991+
ASSERT_STATE_EQUAL(mongocrypt_ctx_state(ctx), MONGOCRYPT_CTX_ERROR);
19911992
} else {
19921993
ASSERT_OK(ret, ctx);
19931994
ASSERT_MONGOCRYPT_BINARY_EQUAL_BSON(tc->expect, got);
@@ -2447,6 +2448,24 @@ static void _test_encrypt_fle2_explicit(_mongocrypt_tester_t *tester) {
24472448
ee_testcase_run(&tc);
24482449
}
24492450

2451+
{
2452+
ee_testcase tc = {0};
2453+
tc.desc = "crossed bounds fails";
2454+
tc.algorithm = MONGOCRYPT_ALGORITHM_RANGE_STR;
2455+
tc.query_type = MONGOCRYPT_QUERY_TYPE_RANGE_STR;
2456+
tc.user_key_id = &keyABC_id;
2457+
tc.contention_factor = OPT_I64(0);
2458+
tc.range_opts = TEST_BSON(RAW_STRING({"min" : {"$numberInt" : "0"}, "max" : {"$numberInt" : "100"}}));
2459+
tc.msg = TEST_BSON(RAW_STRING({
2460+
"v" :
2461+
{"$and" : [ {"age" : {"$gt" : {"$numberInt" : "25"}}}, {"age" : {"$lt" : {"$numberInt" : "15"}}} ]}
2462+
}));
2463+
tc.keys_to_feed[0] = keyABC;
2464+
tc.expect_finalize_error = "must be less than or equal to range max";
2465+
tc.is_expression = true;
2466+
ee_testcase_run(&tc);
2467+
}
2468+
24502469
_mongocrypt_buffer_cleanup(&keyABC_id);
24512470
_mongocrypt_buffer_cleanup(&key123_id);
24522471
}

0 commit comments

Comments
 (0)