MDEV-39219: buffer overflow in PROXY protocol v1 header parsing#4881
MDEV-39219: buffer overflow in PROXY protocol v1 header parsing#4881uwezkhan wants to merge 5 commits intoMariaDB:mainfrom
Conversation
|
uwezkhan06 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
First of all: sign the CLA please: either pick BSD or MariaCLA.
Secondly: Please add a commit message to your commit that's compliant with MariaDB coding standards.
Thirdly: This is a bug. Find the lowest SUPPORTED version this is in and target that instead of main. I'd say 10.11.
And, last but not least: please add a test! There are regression tests for the proxy protocol. Extend these.
|
Thanks for the review and guidance! I’ve updated the patch to:
I’ve also added and registered a regression test for maximum header length in mysql_client_test.c. Please let me know if anything else needs adjustment. |
|
There is a (arguably incorrect) error message from GCC eventhough we compile with C99, it still throughs this "ISO C90" warning, which turns to error in Linux debug compilation. Anyway, can you move that variable declaration at the start of the block, to fix the GCC. |
|
Thanks for pointing that out. I’ve moved the variable declarations to the beginning of the function to comply with the C90-style requirement and avoid the GCC warning. I’ve pushed the updated patch. |
gkodinov
left a comment
There was a problem hiding this comment.
Thanks for working on this. I'll leave the finer points to the final reviewer.
Please:
- squash your commit into a single one
- rebase on 10.11
- Add a commit message to your commit that's compliant with the mariadb coding standards.
This fixes a buffer overflow issue in the PROXY protocol v1 header parsing.
The loop that reads the header could fill the entire buffer and then add a null terminator past the boundary, which leads to an off-by-one overflow.
I updated the loop condition to make sure there is always space left for the null terminator.
Also added a small check to handle cases where the connection closes early, so we don’t process incomplete data.
This change does not affect normal behavior, it just makes the parsing safer.