2022-07-15 15:32:10 +02:00
|
|
|
//golangcitest:args -Egosec
|
2018-05-07 14:02:27 +03:00
|
|
|
package testdata
|
|
|
|
|
|
|
|
import (
|
2022-08-20 18:53:45 +02:00
|
|
|
"crypto/md5" // want "G501: Blocklisted import crypto/md5: weak cryptographic primitive"
|
2019-02-18 11:05:28 +03:00
|
|
|
"fmt"
|
2018-06-10 17:10:56 +03:00
|
|
|
"log"
|
2019-02-18 11:05:28 +03:00
|
|
|
"os"
|
2019-10-08 02:36:21 -04:00
|
|
|
"os/exec"
|
2018-05-07 14:02:27 +03:00
|
|
|
)
|
|
|
|
|
2018-09-01 14:16:30 +03:00
|
|
|
func Gosec() {
|
2022-08-20 18:53:45 +02:00
|
|
|
h := md5.New() // want "G401: Use of weak cryptographic primitive"
|
2018-05-07 14:02:27 +03:00
|
|
|
log.Print(h)
|
|
|
|
}
|
2019-01-08 14:31:04 +03:00
|
|
|
|
|
|
|
func GosecNolintGas() {
|
|
|
|
h := md5.New() //nolint:gas
|
|
|
|
log.Print(h)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GosecNolintGosec() {
|
|
|
|
h := md5.New() //nolint:gosec
|
|
|
|
log.Print(h)
|
|
|
|
}
|
2019-02-18 11:05:28 +03:00
|
|
|
|
|
|
|
func GosecNoErrorCheckingByDefault() {
|
|
|
|
f, _ := os.Create("foo")
|
|
|
|
fmt.Println(f)
|
|
|
|
}
|
2019-10-08 02:36:21 -04:00
|
|
|
|
|
|
|
func GosecG204SubprocWithFunc() {
|
|
|
|
arg := func() string {
|
|
|
|
return "/tmp/dummy"
|
|
|
|
}
|
|
|
|
|
2022-08-20 18:53:45 +02:00
|
|
|
exec.Command("ls", arg()).Run() // want "G204: Subprocess launched with a potential tainted input or cmd arguments"
|
2019-10-08 02:36:21 -04:00
|
|
|
}
|