Skip to content

Commit c71865e

Browse files
committed
CONC-783 Fix potential loss of "Proxy header not accepted from host" error
Send the proxy header and handshake response in a single write. If the client uses two separate send() calls, the server's error message "Proxy header not accepted from host" may be lost. This occurs because the server sends a TCP RST (reset) instead of a FIN if it closes the socket while the client is still sending data. As a result, the client may receive ECONNRESET or EPIPE, without seeing the actual error from the server.
1 parent 77bdf5a commit c71865e

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

include/mariadb_com.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ void ma_net_end(NET *net);
413413
void ma_net_clear(NET *net);
414414
int ma_net_flush(NET *net);
415415
int ma_net_write(NET *net,const unsigned char *packet, size_t len);
416+
int ma_net_write_buff(NET *net, const char *packet, size_t len);
416417
int ma_net_write_command(NET *net,unsigned char command,const char *packet,
417418
size_t len, my_bool disable_flush);
418419
int ma_net_real_write(NET *net,const char *packet, size_t len);

libmariadb/ma_net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ulong net_buffer_length= 8192; /* Default length. Enlarged if necessary */
7373
** can't normally do this the client should have a bigger max-buffer.
7474
*/
7575

76-
static int ma_net_write_buff(NET *net,const char *packet, size_t len);
76+
int ma_net_write_buff(NET *net,const char *packet, size_t len);
7777

7878

7979
/* Init with packet info */
@@ -246,7 +246,7 @@ int ma_net_write_command(NET *net, uchar command,
246246
}
247247

248248

249-
static int ma_net_write_buff(NET *net,const char *packet, size_t len)
249+
int ma_net_write_buff(NET *net,const char *packet, size_t len)
250250
{
251251
size_t left_length;
252252

libmariadb/mariadb_lib.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,17 +1783,6 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,
17831783
goto error;
17841784
}
17851785

1786-
if (mysql->options.extension && mysql->options.extension->proxy_header)
1787-
{
1788-
char *hdr = mysql->options.extension->proxy_header;
1789-
size_t len = mysql->options.extension->proxy_header_len;
1790-
if (ma_pvio_write(pvio, (unsigned char *)hdr, len) <= 0)
1791-
{
1792-
ma_pvio_close(pvio);
1793-
goto error;
1794-
}
1795-
}
1796-
17971786
if (ma_net_init(net, pvio))
17981787
{
17991788
ma_pvio_close(pvio);

plugins/auth/my_auth.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
208208
char *buff, *end;
209209
size_t conn_attr_len= (mysql->options.extension) ?
210210
mysql->options.extension->connect_attrs_len : 0;
211+
size_t proxy_header_len= 0;
212+
char *proxy_header=
213+
(mysql->options.extension) ? mysql->options.extension->proxy_header : NULL;
214+
if (proxy_header)
215+
proxy_header_len= mysql->options.extension->proxy_header_len;
211216

212217
/* see end= buff+32 below, fixed size of the packet is 32 bytes */
213218
buff= malloc(33 + USERNAME_LENGTH + data_len + NAME_LEN + NAME_LEN + conn_attr_len + 9);
@@ -340,6 +345,9 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
340345
Send mysql->client_flag, max_packet_size - unencrypted otherwise
341346
the server does not know we want to do SSL
342347
*/
348+
if (proxy_header_len)
349+
ma_net_write_buff(net, proxy_header, proxy_header_len);
350+
343351
if (ma_net_write(net, (unsigned char *)buff, (size_t) (end-buff)) || ma_net_flush(net))
344352
{
345353
my_set_error(mysql, CR_SERVER_LOST, SQLSTATE_UNKNOWN,
@@ -417,6 +425,8 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio,
417425
*end++= compression_level;
418426
}
419427

428+
if (proxy_header_len)
429+
ma_net_write_buff(net, proxy_header, proxy_header_len);
420430
/* Write authentication package */
421431
if (ma_net_write(net, (unsigned char *)buff, (size_t) (end-buff)) || ma_net_flush(net))
422432
{

0 commit comments

Comments
 (0)