@@ -2239,10 +2239,16 @@ static bool needs_ismaster_check(mongocrypt_ctx_t *ctx) {
2239
2239
2240
2240
// `find_collections_in_pipeline` finds other collection names in an aggregate pipeline that may need schemas.
2241
2241
static bool find_collections_in_pipeline (mc_schema_broker_t * sb ,
2242
- bson_iter_t pipeline_iter ,
2242
+ bson_iter_t * pipeline_iter_ptr ,
2243
2243
const char * db ,
2244
2244
mstr_view path ,
2245
2245
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
+
2246
2252
bson_iter_t array_iter ;
2247
2253
if (!BSON_ITER_HOLDS_ARRAY (& pipeline_iter ) || !bson_iter_recurse (& pipeline_iter , & array_iter )) {
2248
2254
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,
2288
2294
mstr subpath = mstr_append (path , mstrv_lit ("." ));
2289
2295
mstr_inplace_append (& subpath , mstrv_view_cstr (stage_key ));
2290
2296
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 )) {
2292
2298
mstr_free (subpath );
2293
2299
return false;
2294
2300
}
@@ -2311,7 +2317,7 @@ static bool find_collections_in_pipeline(mc_schema_broker_t *sb,
2311
2317
mstr_inplace_append (& subpath , mstrv_view_cstr (stage_key ));
2312
2318
mstr_inplace_append (& subpath , mstrv_lit (".$facet." ));
2313
2319
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 )) {
2315
2321
mstr_free (subpath );
2316
2322
return false;
2317
2323
}
@@ -2347,7 +2353,7 @@ static bool find_collections_in_pipeline(mc_schema_broker_t *sb,
2347
2353
mstr subpath = mstr_append (path , mstrv_lit ("." ));
2348
2354
mstr_inplace_append (& subpath , mstrv_view_cstr (stage_key ));
2349
2355
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 )) {
2351
2357
mstr_free (subpath );
2352
2358
return false;
2353
2359
}
@@ -2374,7 +2380,7 @@ find_collections_in_agg(mongocrypt_binary_t *cmd, mc_schema_broker_t *sb, const
2374
2380
return true;
2375
2381
}
2376
2382
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 );
2378
2384
}
2379
2385
2380
2386
bool mongocrypt_ctx_encrypt_init (mongocrypt_ctx_t * ctx , const char * db , int32_t db_len , mongocrypt_binary_t * cmd ) {
0 commit comments