Merge pull request #20 from roseteromeo56/alert-autofix-1

Potential fix for code scanning alert no. 4: Size computation for allocation may overflow
This commit is contained in:
Romeo Rosete 2025-05-20 11:18:28 -04:00 committed by GitHub
commit e8b2dc2758
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -294,6 +294,9 @@ func (w *trezorDriver) trezorExchange(req proto.Message, results ...proto.Messag
if err != nil { if err != nil {
return 0, err return 0, err
} }
if len(data) > math.MaxInt-8 {
return 0, errors.New("serialized data too large")
}
payload := make([]byte, 8+len(data)) payload := make([]byte, 8+len(data))
copy(payload, []byte{0x23, 0x23}) copy(payload, []byte{0x23, 0x23})
binary.BigEndian.PutUint16(payload[2:], trezor.Type(req)) binary.BigEndian.PutUint16(payload[2:], trezor.Type(req))