Copilot commented on code in PR #3575:
URL: https://github.com/apache/brpc/pull/3575#discussion_r4163508779
##########
src/brpc/policy/mysql/mysql_reply.cpp:
##########
@@ -745,35 +791,45 @@ ParseError MysqlReply::Error::Parse(butil::IOBuf& buf,
butil::Arena* arena) {
return PARSE_OK;
}
MysqlHeader header;
- if (!parse_header(buf, &header)) {
+ butil::IOBuf payload;
+ if (!parse_header(buf, &header, &payload)) {
return PARSE_ERROR_NOT_ENOUGH_DATA;
}
- buf.pop_front(1); // 0xFF
+ // ERR payload: 0xFF(1) + error code(2), followed by either
+ // - protocol-4.1 layout: '#'(1) + sql_state(5) + message, or
+ // - pre-4.1 layout (initial-handshake errors sent before capabilities
+ // are negotiated, e.g. "Too many connections"): the message directly.
+ // Disambiguate by peeking for the '#' marker, like MySQL clients do.
+ payload.pop_front(1); // 0xFF
{
uint8_t tmp[2];
- buf.cutn(tmp, sizeof(tmp));
+ MY_PARSE_CHECK(parse_fixed(payload, tmp, sizeof(tmp)));
_errcode = mysql_uint2korr(tmp);
}
- buf.pop_front(1); // '#'
- // 5 byte server status
- char* status = nullptr;
- MY_ALLOC_CHECK(my_alloc_check(arena, 5, status));
- buf.cutn(status, 5);
- _status.set(status, 5);
+ {
+ // IOBuf::fetch may return a pointer into its own storage instead of
+ // filling the aux buffer, so always dereference the returned pointer.
+ uint8_t aux = 0;
+ const void* peek = payload.fetch(&aux, 1);
+ if (peek != nullptr && *(const uint8_t*)peek == '#') {
Review Comment:
The newly supported legacy ERR layout is misparsed when its message starts
with `#`: `#quota exceeded` becomes message ` exceeded` with SQLSTATE `quota`,
while a short message such as `#bad` is rejected as truncated. The first
message byte cannot reliably distinguish the two layouts. Pass the connection's
protocol/handshake state into ERR parsing and use it to select the layout; add
regression cases for legacy messages starting with `#` alongside protocol-4.1
controls.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]