Skip to content

fix(mysql): validate parameter count for prepared statements#3857

Merged
abonander merged 3 commits into
transact-rs:mainfrom
cvzx:fix/issue-3774-param-validation
Jul 3, 2025
Merged

fix(mysql): validate parameter count for prepared statements#3857
abonander merged 3 commits into
transact-rs:mainfrom
cvzx:fix/issue-3774-param-validation

Conversation

@cvzx
Copy link
Copy Markdown
Contributor

@cvzx cvzx commented May 14, 2025

Does your PR solve an issue?

fixes #3774

Is this a breaking change?

No. This PR adds proper error handling when the number of parameters provided doesn't match the number expected by a prepared statement in MySQL.

@cvzx cvzx force-pushed the fix/issue-3774-param-validation branch from 1d2eba4 to b1caf01 Compare May 14, 2025 02:22
Add validation to ensure the number of provided parameters matches the
expected count for MySQL prepared statements.
This prevents protocol errors by returning an error if the counts do not match before sending
the statement for execution.
@cvzx cvzx force-pushed the fix/issue-3774-param-validation branch from b1caf01 to 149a36c Compare May 14, 2025 02:45
Copy link
Copy Markdown
Contributor

@joeydewaal joeydewaal left a comment

Choose a reason for hiding this comment

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

Like I mentioned, I'm no maintainer but here is some feedback. Also, it is generally recommended to add a regression test when fixing an issue so that might be worth adding.

Comment thread sqlx-mysql/src/connection/executor.rs
Comment thread sqlx-mysql/src/connection/executor.rs
Replace direct Error::Protocol(format!()) calls with err_protocol!
macro in MySQL connection executor.
Copy link
Copy Markdown
Collaborator

@abonander abonander left a comment

Choose a reason for hiding this comment

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

Could you please add a test for this?

- Add test for too few parameters provided to query
- Add test for too many parameters provided to query
- Add test for parameters provided when none expected
- All tests verify Error::Protocol is returned for mismatches

Covers cases for issue transact-rs#3774 parameter validation fix.
@cvzx cvzx requested a review from abonander July 2, 2025 20:41
@abonander abonander merged commit 29549b1 into transact-rs:main Jul 3, 2025
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MySQL query returns "(1835) Malformed communication packet."

3 participants