mirror of
https://github.com/securego/gosec.git
synced 2025-11-27 22:28:20 +02:00
Fix G115 false positive when going from parsed uint to larger int
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
This commit is contained in:
committed by
Cosmin Cojocar
parent
08ea2a57db
commit
9b13cd5ab4
@@ -226,7 +226,12 @@ func isStringToIntConversion(instr *ssa.Convert, dstType string) bool {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
isSafe := bitSizeValue <= dstInt.size && signed == dstInt.signed
|
|
||||||
|
// we're good if:
|
||||||
|
// - signs match and bit size is <= than destination
|
||||||
|
// - parsing unsigned and bit size is < than destination
|
||||||
|
isSafe := (bitSizeValue <= dstInt.size && signed == dstInt.signed) ||
|
||||||
|
(bitSizeValue < dstInt.size && !signed)
|
||||||
return isSafe
|
return isSafe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -426,6 +426,40 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var a string = "13"
|
||||||
|
b, _ := strconv.ParseUint(a, 10, 16)
|
||||||
|
c := int(b)
|
||||||
|
fmt.Printf("%d\n", c)
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
}, 0, gosec.NewConfig()},
|
||||||
|
{[]string{
|
||||||
|
`
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var a string = "13"
|
||||||
|
b, _ := strconv.ParseUint(a, 10, 31)
|
||||||
|
c := int32(b)
|
||||||
|
fmt.Printf("%d\n", c)
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
}, 0, gosec.NewConfig()},
|
||||||
|
{[]string{
|
||||||
|
`
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var a string = "13"
|
var a string = "13"
|
||||||
b, _ := strconv.ParseInt(a, 10, 8)
|
b, _ := strconv.ParseInt(a, 10, 8)
|
||||||
|
|||||||
Reference in New Issue
Block a user