Skip to content

Commit d83911e

Browse files
committed
CDRIVER-5584 delay OP_MSG flag bit access until after opCode check (#1660)
1 parent 81b721a commit d83911e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/libmongoc/src/mongoc/mongoc-cluster.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,10 +3388,24 @@ _mongoc_cluster_run_opmsg_recv (
33883388
_mongoc_buffer_init (&buffer, decompressed_data, decompressed_data_len, NULL, NULL);
33893389
}
33903390

3391-
bson_t body;
3391+
// CDRIVER-5584
3392+
{
3393+
const int32_t op_code = mcd_rpc_header_get_op_code (rpc);
33923394

3393-
uint32_t op_msg_flags = mcd_rpc_op_msg_get_flag_bits (rpc);
3394-
cluster->client->in_exhaust = op_msg_flags & MONGOC_OP_MSG_FLAG_MORE_TO_COME;
3395+
if (op_code != MONGOC_OP_CODE_MSG) {
3396+
RUN_CMD_ERR (MONGOC_ERROR_PROTOCOL,
3397+
MONGOC_ERROR_PROTOCOL_INVALID_REPLY,
3398+
"malformed message from server: expected opCode %" PRId32 ", got %" PRId32,
3399+
MONGOC_OP_CODE_MSG,
3400+
op_code);
3401+
_handle_network_error (cluster, server_stream, error);
3402+
server_stream->stream = NULL;
3403+
network_error_reply (reply, cmd);
3404+
goto done;
3405+
}
3406+
}
3407+
3408+
bson_t body;
33953409

33963410
if (!mcd_rpc_message_get_body (rpc, &body)) {
33973411
RUN_CMD_ERR (MONGOC_ERROR_PROTOCOL, MONGOC_ERROR_PROTOCOL_INVALID_REPLY, "malformed message from server");
@@ -3401,6 +3415,7 @@ _mongoc_cluster_run_opmsg_recv (
34013415
goto done;
34023416
}
34033417

3418+
cluster->client->in_exhaust = (mcd_rpc_op_msg_get_flag_bits (rpc) & MONGOC_OP_MSG_FLAG_MORE_TO_COME) != 0u;
34043419
_mongoc_topology_update_cluster_time (cluster->client->topology, &body);
34053420

34063421
ret = _mongoc_cmd_check_ok (&body, cluster->client->error_api_version, error);

0 commit comments

Comments
 (0)