Skip to content

Commit eeb7a82

Browse files
committed
cursor: split opcode and response_to checks.
1 parent b9b0ebb commit eeb7a82

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/mongoc/mongoc-cursor.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -605,20 +605,29 @@ _mongoc_cursor_get_more (mongoc_cursor_t *cursor)
605605
&cursor->buffer,
606606
cursor->hint,
607607
&cursor->error)) {
608-
goto failure;
608+
GOTO (failure);
609609
}
610610

611-
if ((cursor->rpc.header.opcode != MONGOC_OPCODE_REPLY) ||
612-
(cursor->rpc.header.response_to != request_id)) {
613-
bson_set_error(&cursor->error,
614-
MONGOC_ERROR_PROTOCOL,
615-
MONGOC_ERROR_PROTOCOL_INVALID_REPLY,
616-
"A reply to an invalid request id was received.");
617-
goto failure;
611+
if (cursor->rpc.header.opcode != MONGOC_OPCODE_REPLY) {
612+
bson_set_error (&cursor->error,
613+
MONGOC_ERROR_PROTOCOL,
614+
MONGOC_ERROR_PROTOCOL_INVALID_REPLY,
615+
"Invalid opcode. Expected %d, got %d.",
616+
MONGOC_OPCODE_REPLY, cursor->rpc.header.opcode);
617+
GOTO (failure);
618+
}
619+
620+
if (cursor->rpc.header.response_to != request_id) {
621+
bson_set_error (&cursor->error,
622+
MONGOC_ERROR_PROTOCOL,
623+
MONGOC_ERROR_PROTOCOL_INVALID_REPLY,
624+
"Invalid response_to. Expected %d, got %d.",
625+
request_id, cursor->rpc.header.response_to);
626+
GOTO (failure);
618627
}
619628

620629
if (_mongoc_cursor_unwrap_failure(cursor)) {
621-
goto failure;
630+
GOTO (failure);
622631
}
623632

624633
if (cursor->reader) {

0 commit comments

Comments
 (0)