Skip to content

Commit b24fb3e

Browse files
authored
CPP-776 - test: Ensure mockssandra decodes entire frame (#247)
- Correct mockssandra buffer copy - Replicate C*/DSE's invalid protocol handling - Correct/Simplify header decoding
1 parent b576485 commit b24fb3e

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

cpp-driver/gtests/src/unit/mockssandra.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,7 +1819,7 @@ void ProtocolHandler::decode(ClientConnection* client, const char* data, int32_t
18191819
} else {
18201820
// Not efficient, but concise. Copy the consumed part of the buffer
18211821
// forward then resize the buffer to what's left over.
1822-
std::copy(buffer_.begin(), buffer_.begin() + result, buffer_.begin());
1822+
std::copy(buffer_.begin() + result, buffer_.end(), buffer_.begin());
18231823
buffer_.resize(buffer_.size() - result);
18241824
}
18251825
}
@@ -1838,12 +1838,17 @@ int32_t ProtocolHandler::decode_frame(ClientConnection* client, const char* fram
18381838
remaining--;
18391839
if (version_ < request_handler_->lowest_supported_protocol_version() ||
18401840
version_ > request_handler_->highest_supported_protocol_version()) {
1841-
// Respond using the highest supported protocol that the server
1842-
// supports (don't use the request's version because it's not supported)
1843-
Request::Ptr request(new Request(request_handler_->highest_supported_protocol_version(),
1844-
flags_, stream_, opcode_, String(), client));
1841+
// Use the highest supported protocol version unless it's less than the lowest supported
1842+
// then use the original request's protocol version.
1843+
int8_t response_version = request_handler_->highest_supported_protocol_version();
1844+
if (version_ < request_handler_->lowest_supported_protocol_version()) {
1845+
response_version = version_;
1846+
}
1847+
Request::Ptr request(
1848+
new Request(response_version, flags_, stream_, opcode_, String(), client));
18451849
request_handler_->invalid_protocol(request.get());
1846-
return len - remaining;
1850+
client->close();
1851+
return -1;
18471852
}
18481853
state_ = HEADER;
18491854
break;
@@ -1854,7 +1859,7 @@ int32_t ProtocolHandler::decode_frame(ClientConnection* client, const char* fram
18541859
opcode_ = *pos++;
18551860
pos = decode_int32(pos, end, &length_);
18561861
remaining -= 7;
1857-
} else if (version_ >= 3 && version_ <= 5 && remaining >= 8) {
1862+
} else if (version_ >= 3 && remaining >= 8) {
18581863
flags_ = *pos++;
18591864
pos = decode_int16(pos, end, &stream_);
18601865
opcode_ = *pos++;

0 commit comments

Comments
 (0)