Skip to content

Commit 1d2eba4

Browse files
committed
fix(mysql): validate parameter count for prepared statements
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.
1 parent 92c3845 commit 1d2eba4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sqlx-mysql/src/connection/executor.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ impl MySqlConnection {
123123
.get_or_prepare_statement(sql)
124124
.await?;
125125

126+
if arguments.types.len() != metadata.parameters {
127+
return Err(Error::Protocol(format!(
128+
"Prepared statement expected {} parameters but {} parameters where provided",
129+
metadata.parameters,
130+
arguments.types.len()
131+
).into()));
132+
}
133+
126134
// https://dev.mysql.com/doc/internals/en/com-stmt-execute.html
127135
self.inner.stream
128136
.send_packet(StatementExecute {
@@ -137,6 +145,14 @@ impl MySqlConnection {
137145
.prepare_statement(sql)
138146
.await?;
139147

148+
if arguments.types.len() != metadata.parameters {
149+
return Err(Error::Protocol(format!(
150+
"Prepared statement expected {} parameters but {} parameters where provided",
151+
metadata.parameters,
152+
arguments.types.len()
153+
).into()));
154+
}
155+
140156
// https://dev.mysql.com/doc/internals/en/com-stmt-execute.html
141157
self.inner.stream
142158
.send_packet(StatementExecute {

0 commit comments

Comments
 (0)