Skip to content

Commit cd2fc65

Browse files
authored
Merge pull request github#12101 from owen-mc/go/gofmt-remove-confusing-error-message
Fix files that gofmt can't parse
2 parents 00fe448 + 9ed7836 commit cd2fc65

File tree

5 files changed

+39
-18
lines changed

5 files changed

+39
-18
lines changed

go/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ clean:
2727
rm -rf tools/bin tools/linux64 tools/osx64 tools/win64 tools/net tools/opencsv
2828
rm -rf $(EXTRACTOR_PACK_OUT) build/stats build/testdb
2929

30-
DATAFLOW_BRANCH=main
31-
3230
autoformat:
3331
find ql -iregex '.*\.qll?' -print0 | xargs -0 codeql query format -qq -i
3432
find . -path '**/vendor' -prune -or -type f -iname '*.go' ! -empty -print0 | xargs -0 grep -L "//\s*autoformat-ignore" | xargs gofmt -w

go/ql/src/experimental/CWE-285/PamAuthBad.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
func bad() error {
1+
package main
2+
3+
import "fmt"
4+
5+
func bad() (string, error) {
6+
// ...
27
t, err := pam.StartFunc("", "username", func(s pam.Style, msg string) (string, error) {
38
switch s {
49
case pam.PromptEchoOff:

go/ql/src/experimental/CWE-285/PamAuthGood.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
func good() error {
1+
package main
2+
3+
import "fmt"
4+
5+
func good() (string, error) {
26
t, err := pam.StartFunc("", "username", func(s pam.Style, msg string) (string, error) {
37
switch s {
48
case pam.PromptEchoOff:
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
mySigningKey := []byte("AllYourBase")
1+
package main
22

3-
claims := &jwt.RegisteredClaims{
4-
ExpiresAt: jwt.NewNumericDate(time.Unix(1516239022, 0)),
5-
Issuer: "test",
6-
}
3+
import "time"
4+
5+
func bad() {
6+
mySigningKey := []byte("AllYourBase")
77

8-
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
9-
ss, err := token.SignedString(mySigningKey)
8+
claims := &jwt.RegisteredClaims{
9+
ExpiresAt: jwt.NewNumericDate(time.Unix(1516239022, 0)),
10+
Issuer: "test",
11+
}
12+
13+
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
14+
ss, err := token.SignedString(mySigningKey)
15+
}

go/ql/src/experimental/CWE-321/HardcodedKeysGood.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
package main
2+
3+
import (
4+
"math/big"
5+
"time"
6+
)
7+
18
func GenerateCryptoString(n int) (string, error) {
29
const chars = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
310
ret := make([]byte, n)
@@ -11,13 +18,14 @@ func GenerateCryptoString(n int) (string, error) {
1118
return string(ret), nil
1219
}
1320

14-
mySigningKey := GenerateCryptoString(64)
21+
func good() {
22+
mySigningKey := GenerateCryptoString(64)
1523

24+
claims := &jwt.RegisteredClaims{
25+
ExpiresAt: jwt.NewNumericDate(time.Unix(1516239022, 0)),
26+
Issuer: "test",
27+
}
1628

17-
claims := &jwt.RegisteredClaims{
18-
ExpiresAt: jwt.NewNumericDate(time.Unix(1516239022, 0)),
19-
Issuer: "test",
29+
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
30+
ss, err := token.SignedString(mySigningKey)
2031
}
21-
22-
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
23-
ss, err := token.SignedString(mySigningKey)

0 commit comments

Comments
 (0)