Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions sql/net_serv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ my_real_read(NET *net, size_t *complen,
size_t length;
uint i,retry_count=0;
ulong len=packet_error;
bool proxy_parsed= false;
my_bool expect_error_packet __attribute__((unused))= 0;
thr_alarm_t alarmed;
#ifndef NO_ALARM
Expand Down Expand Up @@ -1253,16 +1254,21 @@ my_real_read(NET *net, size_t *complen,

packets_out_of_order:
{
switch (handle_proxy_header(net)) {
case ABORT:
if (!proxy_parsed)
{
switch (handle_proxy_header(net))
{
case ABORT:
/* error happened, message is already written. */
len= packet_error;
goto end;
case RETRY:
goto end;
case RETRY:
proxy_parsed= true;
goto retry;
case IGNORE:
case IGNORE:
break;
}
}
}

DBUG_PRINT("error",
("Packets out of order (Found: %d, expected %u)",
Expand Down
18 changes: 18 additions & 0 deletions tests/mysql_client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -20786,6 +20786,23 @@ static void test_proxy_header_limits()
mysql_close(m);
}

/* Test that connection fails with multiple proxy headers (MDEV-40878) */
static void test_proxy_header_multiple()
{
MYSQL *m;
const char header[]= "PROXY TCP4 192.0.2.1 127.0.0.1 12345 3306\r\n"
"PROXY TCP4 192.0.2.2 127.0.0.1 12346 3306\r\n";
myheader("test_proxy_header_multiple");

m = mysql_client_init(NULL);
DIE_UNLESS(m);
mysql_optionsv(m, MARIADB_OPT_PROXY_HEADER, header, sizeof(header)-1);

/* Connection should fail, second proxy header is interpreted as packet error */
DIE_UNLESS(mysql_real_connect(m, opt_host, "root", "", NULL, opt_port, opt_unix_socket, 0) == NULL);
mysql_close(m);
}


/*
MDEV-37556 memory leak in proxy protocol for non-loopback
Expand Down Expand Up @@ -21095,6 +21112,7 @@ static void test_proxy_header()
test_proxy_header_localhost();
test_proxy_header_ignore();
test_proxy_header_limits();
test_proxy_header_multiple();
test_proxy_header_dbug_remote_connection();
test_proxy_header_connect_errors_reset();
test_proxy_header_proxy_host_connect_errors_reset();
Expand Down