Skip to content

Commit

Permalink
fix: correct initial CodeQL findings
Browse files Browse the repository at this point in the history
- Incorrect conversion between integer types
- Size computation for allocation may overflow
  • Loading branch information
dnwe committed Apr 28, 2021
1 parent 1c17804 commit bcc611e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
12 changes: 10 additions & 2 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,11 @@ func (ca *clusterAdmin) DescribeConfig(resource ConfigResource) ([]ConfigEntry,

// DescribeConfig of broker/broker logger must be sent to the broker in question
if dependsOnSpecificNode(resource) {
id, _ := strconv.Atoi(resource.Name)
var id int64
id, err = strconv.ParseInt(resource.Name, 10, 32)
if err != nil {
return nil, err
}
b, err = ca.findBroker(int32(id))
} else {
b, err = ca.findAnyBroker()
Expand Down Expand Up @@ -670,7 +674,11 @@ func (ca *clusterAdmin) AlterConfig(resourceType ConfigResourceType, name string

// AlterConfig of broker/broker logger must be sent to the broker in question
if dependsOnSpecificNode(ConfigResource{Name: name, Type: resourceType}) {
id, _ := strconv.Atoi(name)
var id int64
id, err = strconv.ParseInt(name, 10, 32)
if err != nil {
return err
}
b, err = ca.findBroker(int32(id))
} else {
b, err = ca.findAnyBroker()
Expand Down
2 changes: 1 addition & 1 deletion broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ func (b *Broker) encode(pe packetEncoder, version int16) (err error) {
return err
}

port, err := strconv.Atoi(portstr)
port, err := strconv.ParseInt(portstr, 10, 32)
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions gssapi_kerberos.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package sarama
import (
"encoding/asn1"
"encoding/binary"
"errors"
"fmt"
"io"
"math"
"strings"
"time"

Expand Down Expand Up @@ -61,6 +63,9 @@ type KerberosClient interface {

func (krbAuth *GSSAPIKerberosAuth) writePackage(broker *Broker, payload []byte) (int, error) {
length := len(payload)
if length+4 > math.MaxUint32 {
return 0, errors.New("payload too large, will overflow uint32")
}
finalPackage := make([]byte, length+4) //4 byte length header + payload
copy(finalPackage[4:], payload)
binary.BigEndian.PutUint32(finalPackage, uint32(length))
Expand Down

0 comments on commit bcc611e

Please sign in to comment.