Skip to content

server: Correctly handle COM_STMT_EXECUTE without rebind #984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions server/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ func (c *Conn) handleStmtExecute(data []byte) (*mysql.Result, error) {
pos += paramNum << 1

paramValues = data[pos:]
}

if err := c.bindStmtArgs(s, nullBitmaps, paramTypes, paramValues); err != nil {
return nil, errors.Trace(err)
if err := c.bindStmtArgs(s, nullBitmaps, paramTypes, paramValues); err != nil {
return nil, errors.Trace(err)
}
}
}

Expand All @@ -176,6 +176,14 @@ func (c *Conn) handleStmtExecute(data []byte) (*mysql.Result, error) {
func (c *Conn) bindStmtArgs(s *Stmt, nullBitmap, paramTypes, paramValues []byte) error {
args := s.Args

// Every param should have a type-and-flag of 2 bytes
// 0xfe80 == Type 0xfe and Flag 0x80
// The flag only has one bit and that indicates if it is unsigned or not.
// Types are 1 byte, but might grow into the 7 unused bits in the future.
if len(paramTypes)/2 != s.Params {
return mysql.ErrMalformPacket
}

pos := 0

var v []byte
Expand All @@ -190,7 +198,7 @@ func (c *Conn) bindStmtArgs(s *Stmt, nullBitmap, paramTypes, paramValues []byte)
}

tp := paramTypes[i<<1]
isUnsigned := (paramTypes[(i<<1)+1] & 0x80) > 0
isUnsigned := (paramTypes[(i<<1)+1] & mysql.PARAM_UNSIGNED) > 0

switch tp {
case mysql.MYSQL_TYPE_NULL:
Expand Down
Loading