Skip to content

Commit

Permalink
go/mysql: conn.go: Fix read-after-recycle bug of the packet byte buff…
Browse files Browse the repository at this point in the history
…er in COM_STMT_SEND_LONG_DATA.

Back ports vitessio@24820d8
  • Loading branch information
reltuk committed Feb 28, 2025
1 parent a0ed461 commit 3239bb6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 1 addition & 4 deletions go/mysql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ func (c *Conn) handleNextCommand(ctx context.Context, handler Handler) error {
return err
}
case ComStmtSendLongData:
stmtID, paramID, chunkData, ok := c.parseComStmtSendLongData(data)
stmtID, paramID, chunk, ok := c.parseComStmtSendLongData(data)
c.recycleReadPacket()
if !ok {
err := fmt.Errorf("error parsing statement send long data from client %v, returning error: %v", c.ConnectionID, data)
Expand All @@ -1259,9 +1259,6 @@ func (c *Conn) handleNextCommand(ctx context.Context, handler Handler) error {
return err
}

chunk := make([]byte, len(chunkData))
copy(chunk, chunkData)

key := fmt.Sprintf("v%d", paramID+1)
if val, ok := prepare.BindVars[key]; ok {
val.Value = append(val.Value, chunk...)
Expand Down
6 changes: 5 additions & 1 deletion go/mysql/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,11 @@ func (c *Conn) parseComStmtSendLongData(data []byte) (uint32, uint16, []byte, bo
return 0, 0, nil, false
}

return statementID, paramID, data[pos:], true
chunkData := data[pos:]
chunk := make([]byte, len(chunkData))
copy(chunk, chunkData)

return statementID, paramID, chunk, true
}

func (c *Conn) parseComStmtClose(data []byte) (uint32, bool) {
Expand Down

0 comments on commit 3239bb6

Please sign in to comment.