Skip to content

MDEV-25817 proxy protocol: successful login does not reset connect errors#5292

Closed
vaintroub wants to merge 2 commits into
mainfrom
MDEV-25817-proxy-protocol-connect-errors-reset
Closed

MDEV-25817 proxy protocol: successful login does not reset connect errors#5292
vaintroub wants to merge 2 commits into
mainfrom
MDEV-25817-proxy-protocol-connect-errors-reset

Conversation

@vaintroub

Copy link
Copy Markdown
Member

With proxy protocol thd_set_peer_addr() runs twice (proxy host, then the real client from the proxy header). Connect errors are accounted against the real client, but check_connection() incorrectly uses condition on the proxy host's count, rather than real client's address.

Fix: reset both the proxy host, and real client's connect errors on successful connection.

Added tests for incomplete handshake, and reset behavior, under proxy protocol, for both real client errors, and proxy host errors.

Analysis:
The collation is hard coded.

Fix:
The table initially had system character set hardcoded. However,
a table field should derive character set and collation from
table and table should derive it from database. Hence made
necessary change to reflect that.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue where a successful login under the PROXY protocol did not reset the connect-error counter for the proxied client and the proxy host. It introduces a new flag have_proxy_protocol_connect_errors to track connection errors and ensures both the socket peer and the real client have their connection error counters reset upon successful authentication. Additionally, test cases are added to verify this behavior. The review feedback correctly points out that the ip array in sql_connect.cc and the host_errors variable in net_serv.cc are declared but not initialized, which could lead to reading uninitialized memory.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread sql/sql_connect.cc
int auth_rc;
NET *net= &thd->net;
/* Socket peer IP address, the proxy host under PROXY protocol */
char ip[NI_MAXHOST];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ip array is declared but not initialized. If there is any path where connect_errors is non-zero but ip has not been populated (or if vio_peer_addr fails/is skipped), passing ip to reset_host_connect_errors will result in reading uninitialized stack memory. Initializing it to zero prevents potential undefined behavior and compiler/static analyzer warnings.

  char ip[NI_MAXHOST]= {0};

Comment thread sql/net_serv.cc Outdated
@@ -960,9 +962,13 @@ static handle_proxy_header_result handle_proxy_header(NET *net)
/* Change peer address in THD and ACL structures.*/
uint host_errors;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The host_errors variable is declared but not initialized. If thd_set_peer_addr returns early or fails without writing to host_errors, it will contain garbage when checked in if (host_errors). Initializing it to 0 ensures safe and predictable behavior.

  uint host_errors= 0;

…rors

With proxy protocol thd_set_peer_addr() runs twice (proxy host, then the
real client from the proxy header). Connect errors are accounted against
the real client, but check_connection() incorrectly uses condition on the
proxy host's count, rather than real client's address.

Fix: reset both the proxy host, and real client's connect errors on
successful connection.

Added tests for incomplete handshake, and reset behavior,
under proxy protocol, for both real client errors, and proxy host errors.
@vaintroub vaintroub force-pushed the MDEV-25817-proxy-protocol-connect-errors-reset branch from a2d3985 to 8744ed8 Compare June 29, 2026 09:54
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ vaintroub
❌ mariadb-RuchaDeodhar
You have signed the CLA already but the status is still pending? Let us recheck it.

@vaintroub vaintroub closed this Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants