Fix PROXY protocol detection in MySQL_Data_Stream::read_from_net

When pkts_recv==0, the code reads 4 bytes expecting a MySQL packet header,
but PROXY protocol starts with 'PROXY ' which gets misinterpreted as a
MySQL header with a huge packet length (0x504f5250 = ~1.3GB).

Add check for 'PROX' prefix before parsing as MySQL header. This prevents
passing an incorrect length parameter to recv() that exceeds the buffer size.

Fixes #5376
v3.0-test0213
Rene Cannao 1 week ago
parent 11a43bf768
commit 37e72ea3f9

@ -589,10 +589,18 @@ int MySQL_Data_Stream::read_from_net() {
// to avoid issue with SSL, we will only read the header and eventually the first packet
r = recv(fd, queue_w_ptr(queueIN), 4, 0);
if (r == 4) {
// let's try to read a whole packet
mysql_hdr Hdr;
memcpy(&Hdr,queueIN.buffer,sizeof(mysql_hdr));
r += recv(fd, queue_w_ptr(queueIN)+4, Hdr.pkt_length, 0);
// Check for PROXY protocol before treating as MySQL header
// PROXY protocol starts with "PROXY " (6 bytes), but we only have 4 bytes here
// If first 4 bytes are "PROX", don't interpret as MySQL header
if (strncmp((char *)queueIN.buffer, "PROX", 4) == 0) {
// PROXY protocol detected - read more data without MySQL header parsing
r += recv(fd, queue_w_ptr(queueIN)+4, s-4, 0);
} else {
// let's try to read a whole packet
mysql_hdr Hdr;
memcpy(&Hdr,queueIN.buffer,sizeof(mysql_hdr));
r += recv(fd, queue_w_ptr(queueIN)+4, Hdr.pkt_length, 0);
}
}
} else {
r = recv(fd, queue_w_ptr(queueIN), s, 0);

Loading…
Cancel
Save