Skip to content

Commit 7d799f5

Browse files
authored
MONGOCRYPT-784 avoid passing over-aligned bson_iter_t by value in parameters (#971)
1 parent 15d82f5 commit 7d799f5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/mongocrypt-ctx-encrypt.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,10 +2239,16 @@ static bool needs_ismaster_check(mongocrypt_ctx_t *ctx) {
22392239

22402240
// `find_collections_in_pipeline` finds other collection names in an aggregate pipeline that may need schemas.
22412241
static bool find_collections_in_pipeline(mc_schema_broker_t *sb,
2242-
bson_iter_t pipeline_iter,
2242+
bson_iter_t *pipeline_iter_ptr,
22432243
const char *db,
22442244
mstr_view path,
22452245
mongocrypt_status_t *status) {
2246+
BSON_ASSERT_PARAM(sb);
2247+
BSON_ASSERT_PARAM(pipeline_iter_ptr);
2248+
BSON_ASSERT_PARAM(db);
2249+
2250+
bson_iter_t pipeline_iter = *pipeline_iter_ptr; // Operate on a copy.
2251+
22462252
bson_iter_t array_iter;
22472253
if (!BSON_ITER_HOLDS_ARRAY(&pipeline_iter) || !bson_iter_recurse(&pipeline_iter, &array_iter)) {
22482254
CLIENT_ERR("failed to recurse pipeline at path: %s", path.data);
@@ -2288,7 +2294,7 @@ static bool find_collections_in_pipeline(mc_schema_broker_t *sb,
22882294
mstr subpath = mstr_append(path, mstrv_lit("."));
22892295
mstr_inplace_append(&subpath, mstrv_view_cstr(stage_key));
22902296
mstr_inplace_append(&subpath, mstrv_lit(".$lookup.pipeline"));
2291-
if (!find_collections_in_pipeline(sb, lookup_iter, db, subpath.view, status)) {
2297+
if (!find_collections_in_pipeline(sb, &lookup_iter, db, subpath.view, status)) {
22922298
mstr_free(subpath);
22932299
return false;
22942300
}
@@ -2311,7 +2317,7 @@ static bool find_collections_in_pipeline(mc_schema_broker_t *sb,
23112317
mstr_inplace_append(&subpath, mstrv_view_cstr(stage_key));
23122318
mstr_inplace_append(&subpath, mstrv_lit(".$facet."));
23132319
mstr_inplace_append(&subpath, mstrv_view_cstr(field));
2314-
if (!find_collections_in_pipeline(sb, facet_iter, db, subpath.view, status)) {
2320+
if (!find_collections_in_pipeline(sb, &facet_iter, db, subpath.view, status)) {
23152321
mstr_free(subpath);
23162322
return false;
23172323
}
@@ -2347,7 +2353,7 @@ static bool find_collections_in_pipeline(mc_schema_broker_t *sb,
23472353
mstr subpath = mstr_append(path, mstrv_lit("."));
23482354
mstr_inplace_append(&subpath, mstrv_view_cstr(stage_key));
23492355
mstr_inplace_append(&subpath, mstrv_lit(".$unionWith.pipeline"));
2350-
if (!find_collections_in_pipeline(sb, unionWith_iter, db, subpath.view, status)) {
2356+
if (!find_collections_in_pipeline(sb, &unionWith_iter, db, subpath.view, status)) {
23512357
mstr_free(subpath);
23522358
return false;
23532359
}
@@ -2374,7 +2380,7 @@ find_collections_in_agg(mongocrypt_binary_t *cmd, mc_schema_broker_t *sb, const
23742380
return true;
23752381
}
23762382

2377-
return find_collections_in_pipeline(sb, iter, db, mstrv_lit("aggregate.pipeline"), status);
2383+
return find_collections_in_pipeline(sb, &iter, db, mstrv_lit("aggregate.pipeline"), status);
23782384
}
23792385

23802386
bool mongocrypt_ctx_encrypt_init(mongocrypt_ctx_t *ctx, const char *db, int32_t db_len, mongocrypt_binary_t *cmd) {

0 commit comments

Comments
 (0)