Skip to content

Commit

Permalink
Merge pull request #249 from cole-miller/fix-params
Browse files Browse the repository at this point in the history
Fix int overflow on 32-bit archs
  • Loading branch information
Mathieu Borderé committed May 2, 2023
2 parents 49cc09c + 2a66817 commit 71dcd75
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func (c *Conn) Prepare(query string) (driver.Stmt, error) {

// ExecContext is an optional interface that may be implemented by a Conn.
func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
if len(args) > math.MaxUint32 {
if int64(len(args)) > math.MaxUint32 {
return nil, driverError(c.log, fmt.Errorf("too many parameters (%d)", len(args)))
} else if len(args) > math.MaxUint8 {
protocol.EncodeExecSQLV1(&c.request, uint64(c.id), query, args)
Expand Down Expand Up @@ -416,7 +416,7 @@ func (c *Conn) Query(query string, args []driver.Value) (driver.Rows, error) {

// QueryContext is an optional interface that may be implemented by a Conn.
func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
if len(args) > math.MaxUint32 {
if int64(len(args)) > math.MaxUint32 {
return nil, driverError(c.log, fmt.Errorf("too many parameters (%d)", len(args)))
} else if len(args) > math.MaxUint8 {
protocol.EncodeQuerySQLV1(&c.request, uint64(c.id), query, args)
Expand Down Expand Up @@ -576,7 +576,7 @@ func (s *Stmt) NumInput() int {
//
// ExecContext must honor the context timeout and return when it is canceled.
func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
if len(args) > math.MaxUint32 {
if int64(len(args)) > math.MaxUint32 {
return nil, driverError(s.log, fmt.Errorf("too many parameters (%d)", len(args)))
} else if len(args) > math.MaxUint8 {
protocol.EncodeExecV1(s.request, s.db, s.id, args)
Expand Down Expand Up @@ -615,7 +615,7 @@ func (s *Stmt) Exec(args []driver.Value) (driver.Result, error) {
//
// QueryContext must honor the context timeout and return when it is canceled.
func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
if len(args) > math.MaxUint32 {
if int64(len(args)) > math.MaxUint32 {
return nil, driverError(s.log, fmt.Errorf("too many parameters (%d)", len(args)))
} else if len(args) > math.MaxUint8 {
protocol.EncodeQueryV1(s.request, s.db, s.id, args)
Expand Down
2 changes: 1 addition & 1 deletion internal/protocol/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (m *Message) putNamedValues32(values NamedValues) {
l := len(values)
if l == 0 {
return
} else if l > math.MaxUint32 {
} else if int64(l) > math.MaxUint32 {
// safeguard, should have been checked beforehand.
panic("too many parameters")
}
Expand Down

0 comments on commit 71dcd75

Please sign in to comment.