Skip to content

Commit

Permalink
Fix false positive in conversion overflow check from uint8/int8 type
Browse files Browse the repository at this point in the history
Change-Id: I543545e22fa12de0d85dcf92664a0a54e8f7244a
Signed-off-by: Cosmin Cojocar <[email protected]>
  • Loading branch information
ccojocar committed Aug 22, 2024
1 parent a39ec5a commit ab3f6c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion analyzers/conversion_overflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type integer struct {
}

func parseIntType(intType string) (integer, error) {
re := regexp.MustCompile(`(?P<type>u?int)(?P<size>\d{2})?`)
re := regexp.MustCompile(`(?P<type>u?int)(?P<size>\d{1,2})?`)
matches := re.FindStringSubmatch(intType)
if matches == nil {
return integer{}, fmt.Errorf("no integer type match found for %s", intType)
Expand Down
30 changes: 30 additions & 0 deletions testutils/g115_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,34 @@ func main() {
}
`,
}, 1, gosec.NewConfig()},
{[]string{
`
package main
import (
"fmt"
)
func main() {
a := "A\xFF"
b := int64(a[0])
fmt.Printf("%d\n", b)
}
`,
}, 0, gosec.NewConfig()},
{[]string{
`
package main
import (
"fmt"
)
func main() {
var a uint8 = 13
b := int(a)
fmt.Printf("%d\n", b)
}
`,
}, 0, gosec.NewConfig()},
}

0 comments on commit ab3f6c1

Please sign in to comment.