Skip to content

Commit 9ed7836

Browse files
committed
Fix files that gofmt can't parse
We have some .go files that gofmt can't parse because they don't start with "package". This was intentional, as they are fragments to be included in .qhelp files. They don't affect the return code as gofmt doesn't change their formatting, so this wasn't changing the result of the check. However, it was confusing that when the check failed because some other files weren't formatted correctly, the user would see the stderr complaining about those files, so we capture stderr. It would be an improvement to print which files are not formatted correctly, but that was beyond my abilities with bash and makefiles.
1 parent 2f637e2 commit 9ed7836

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

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)