MDEV-40867 CONNECT writes unvalidated data from remote filter into fixed-len buffer - #5599
Conversation
grooverdan
left a comment
There was a problem hiding this comment.
10.6 has had its last release, so can this be rebased to 10.11 please.
| return FALSE; | ||
| } // end of InitTableList | ||
|
|
||
| #define OP_SIZE 7 |
There was a problem hiding this comment.
A description as to why 7 would be useful.
There was a problem hiding this comment.
It is same as previously hardcoded value, no change
3751866 to
ff62167
Compare
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
LGTM. Please stand by for the final reviewer.
|
FYI: According to our development cycle we work on bugs In the following periods 15 Mar-30 Apr, 15 Jun-30 Jul, 15 Sep-30 Oct and 15 Dec-31 Jan. So, please, expect to get a review somewhere between these two dates and the goal is to have your PR merged before the second date |
There was a problem hiding this comment.
Pull request overview
This PR addresses MDEV-40867 in the CONNECT storage engine by preventing stack buffer overflows in TDBTBL::TestFil() when re-parsing pushed-down TABID filters containing oversized values, and adds an MTR regression test to ensure the server no longer crashes.
Changes:
- Bound
sscanfreads for theTABIDoperator token and string value parsing to prevent writing past fixed-length stack buffers. - Applied the same bounded parsing for values extracted from
IN (...)filters. - Extended the existing
connect.tblMTR test coverage to include oversizedTABIDfilter inputs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| storage/connect/tabtbl.cpp | Adds width limits to sscanf parsing in TDBTBL::TestFil() to prevent buffer overflows. |
| storage/connect/mysql-test/connect/t/tbl.test | Adds regression queries to verify oversized TABID filters don’t crash and behave as expected. |
| storage/connect/mysql-test/connect/r/tbl.result | Updates expected output for the new regression coverage. |
Suppressed comments (1)
storage/connect/mysql-test/connect/t/tbl.test:89
- The trailing marker
End of 10.11 testsis misleading in a generic MTR test file and looks like a copy/paste artifact. Consider making this version-neutral to avoid confusion when the test is run on other branches/versions.
--echo # End of 10.11 tests
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…xed-len buffer TestFil() in storage/connect/tabtbl.cpp uses unbounded sscanf format specifiers to parse TABID filter values pushed from ha_connect::CheckCond(). When a WHERE tabname='...' filter exceeds NAME_LEN bytes (192), sscanf overflows the stack-allocated tn[NAME_LEN] buffer, corrupting the stack and crashing mysqld with SIGSEGV. Fix: add width specifiers to bound all sscanf writes: - %7s for op[8] - %192[^'] for tn (NAME_LEN bytes + null terminator) All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.
Description
This PR fixes MDEV-40867 where
TDBTBL::TestFil()in the CONNECT storage engine crashes with SIGSEGV when aTABLE_TYPE=TBLtable receives an oversized TABID filter value.TDBTBL::TestFil()re-parses condition-pushed filter strings usingsscanf(fil, "TABID = '%[^']'", tn)wheretnis a fixed 192-byte stack buffer (char tn[NAME_LEN]). Since%[^']is unbounded, a filter value exceeding 192 bytes overflowstn, corrupts the stack, and crashesmysqld.The fix involves:
%192[^']width specifier to bound writes intotn[NAME_LEN](192 chars + null = 193 bytes)%7swidth specifier to bound writes intoop[8](7 chars + null = 8 bytes)IN (...)loop that parses individual values back intotnHow can this PR be tested?
Run the MTR test:
Or manually:
Results from my testing
Server crashed with SIGSEGV. Confirmed on MariaDB 10.6.28, 10.11.18, 11.4.12, 11.8.8, and 12.3.2.
Server stays alive. Normal TABID filtering works correctly. Existing
connect.tblMTR test passes with no regression.Basing the PR against the correct MariaDB version
PR quality check
CODING_STANDARDS.mdfile and my PR conforms to this where appropriate.