Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit d05657d

Browse files
committed
Make the gofmt CI test actaully fatal
Turns out gofmt doesn't actually return 1 when it finds problems, only when it finds source files which don't compile (all of which are now excluded). This also fixes existing overlooked inconsistencies as a result of this mistake.
1 parent 302eb55 commit d05657d

11 files changed

Lines changed: 76 additions & 75 deletions

File tree

.github/workflows/codeqltest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: env PATH=$PATH:$HOME/codeql make
3535

3636
- name: Check that all QL and Go code is autoformatted
37-
run: env PATH=$PATH:$HOME/codeql make QL_AUTOFORMAT=--check-only GO_AUTOFORMAT=-d autoformat
37+
run: env PATH=$PATH:$HOME/codeql make check-formatting
3838

3939
- name: Test
4040
run: env PATH=$PATH:$HOME/codeql make test

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@ EXTRACTOR_PACK_OUT = build/codeql-extractor-go
2121
BINARIES = go-extractor go-tokenizer go-autobuilder go-bootstrap go-gen-dbscheme
2222

2323
.PHONY: tools tools-codeql tools-codeql-full clean autoformat \
24-
tools-linux64 tools-osx64 tools-win64
24+
tools-linux64 tools-osx64 tools-win64 check-formatting
2525

2626
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-
QL_AUTOFORMAT=-qq -i
31-
GO_AUTOFORMAT=-w # Update files in-place
32-
3330
DATAFLOW_BRANCH=master
3431

3532
autoformat:
36-
find ql/src -name "*.ql" -or -name "*.qll" | xargs codeql query format $(QL_AUTOFORMAT)
37-
git ls-files | grep \\.go$ | xargs grep -L "//\s*autoformat-ignore" | xargs gofmt $(GO_AUTOFORMAT)
33+
find ql/src -name "*.ql" -or -name "*.qll" | xargs codeql query format -qq -i
34+
git ls-files | grep \\.go$ | xargs grep -L "//\s*autoformat-ignore" | xargs gofmt -w
35+
36+
check-formatting:
37+
find ql/src -name "*.ql" -or -name "*.qll" | xargs codeql query format --check-only
38+
test -z "$$(git ls-files | grep \\.go$ | xargs grep -L "//\s*autoformat-ignore" | xargs gofmt -l)"
3839

3940
tools: $(addsuffix $(EXE),$(addprefix tools/bin/,$(BINARIES))) tools/tokenizer.jar
4041

extractor/gomodextractor.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,9 @@ func extractGoModComments(tw *trap.Writer, expr modfile.Expr, exprlbl trap.Label
172172
extractLocation(tw, grouplbl, startLine, startCol, endLine, endCol)
173173
}
174174

175-
176-
177175
func extractGoModComment(tw *trap.Writer, comment modfile.Comment, commentToken string, grouplbl trap.Label, idx int) {
178176
lbl := tw.Labeler.LocalID(comment)
179177
dbscheme.CommentsTable.Emit(tw, lbl, dbscheme.SlashSlashComment.Index(), grouplbl, idx, commentToken)
180178

181-
extractLocation(tw, lbl, comment.Start.Line, comment.Start.LineRune, comment.Start.Line, comment.Start.LineRune + (len(commentToken) - 1))
179+
extractLocation(tw, lbl, comment.Start.Line, comment.Start.LineRune, comment.Start.Line, comment.Start.LineRune+(len(commentToken)-1))
182180
}

ql/src/experimental/CWE-322/InsecureHostKeyCallbackExample.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ func main() {}
99

1010
func insecureIgnoreHostKey() {
1111
_ = &ssh.ClientConfig{
12-
User: "username",
13-
Auth: []ssh.AuthMethod{nil},
12+
User: "username",
13+
Auth: []ssh.AuthMethod{nil},
1414
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
1515
}
1616
}
@@ -22,6 +22,6 @@ func insecureHostKeyCallback() {
2222
HostKeyCallback: ssh.HostKeyCallback(
2323
func(hostname string, remote net.Addr, key ssh.PublicKey) error {
2424
return nil
25-
}),
25+
}),
2626
}
27-
}
27+
}

ql/src/experimental/CWE-322/SecureHostKeyCallbackExample.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ func secureHostKeyCallback() {
1212
publicKey, _ := ssh.ParsePublicKey(publicKeyBytes)
1313

1414
_ = &ssh.ClientConfig{
15-
User: "username",
16-
Auth: []ssh.AuthMethod{nil},
15+
User: "username",
16+
Auth: []ssh.AuthMethod{nil},
1717
HostKeyCallback: ssh.FixedHostKey(publicKey),
1818
}
19-
}
19+
}
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
edges
2-
| InsecureHostKeyCallbackExample.go:12:4:14:3 | function literal : signature type | InsecureHostKeyCallbackExample.go:11:20:14:4 | type conversion |
3-
| InsecureHostKeyCallbackExample.go:27:14:30:3 | type conversion : signature type | InsecureHostKeyCallbackExample.go:35:20:35:27 | callback |
4-
| InsecureHostKeyCallbackExample.go:28:3:30:2 | function literal : signature type | InsecureHostKeyCallbackExample.go:27:14:30:3 | type conversion : signature type |
5-
| InsecureHostKeyCallbackExample.go:41:3:43:2 | function literal : signature type | InsecureHostKeyCallbackExample.go:48:20:48:48 | type conversion |
2+
| InsecureHostKeyCallbackExample.go:12:4:14:4 | function literal : signature type | InsecureHostKeyCallbackExample.go:11:20:14:5 | type conversion |
3+
| InsecureHostKeyCallbackExample.go:27:14:30:4 | type conversion : signature type | InsecureHostKeyCallbackExample.go:35:20:35:27 | callback |
4+
| InsecureHostKeyCallbackExample.go:28:3:30:3 | function literal : signature type | InsecureHostKeyCallbackExample.go:27:14:30:4 | type conversion : signature type |
5+
| InsecureHostKeyCallbackExample.go:41:3:43:3 | function literal : signature type | InsecureHostKeyCallbackExample.go:48:20:48:48 | type conversion |
66
| InsecureHostKeyCallbackExample.go:52:39:52:46 | definition of callback : HostKeyCallback | InsecureHostKeyCallbackExample.go:56:20:56:27 | callback |
77
| InsecureHostKeyCallbackExample.go:52:39:52:46 | definition of callback : signature type | InsecureHostKeyCallbackExample.go:56:20:56:27 | callback |
8-
| InsecureHostKeyCallbackExample.go:63:22:66:3 | type conversion : signature type | InsecureHostKeyCallbackExample.go:68:35:68:50 | insecureCallback : signature type |
9-
| InsecureHostKeyCallbackExample.go:64:3:66:2 | function literal : signature type | InsecureHostKeyCallbackExample.go:63:22:66:3 | type conversion : signature type |
8+
| InsecureHostKeyCallbackExample.go:63:22:66:4 | type conversion : signature type | InsecureHostKeyCallbackExample.go:68:35:68:50 | insecureCallback : signature type |
9+
| InsecureHostKeyCallbackExample.go:64:3:66:3 | function literal : signature type | InsecureHostKeyCallbackExample.go:63:22:66:4 | type conversion : signature type |
1010
| InsecureHostKeyCallbackExample.go:68:35:68:50 | insecureCallback : signature type | InsecureHostKeyCallbackExample.go:52:39:52:46 | definition of callback : signature type |
1111
| InsecureHostKeyCallbackExample.go:79:35:79:61 | call to InsecureIgnoreHostKey : HostKeyCallback | InsecureHostKeyCallbackExample.go:52:39:52:46 | definition of callback : HostKeyCallback |
1212
nodes
13-
| InsecureHostKeyCallbackExample.go:11:20:14:4 | type conversion | semmle.label | type conversion |
14-
| InsecureHostKeyCallbackExample.go:12:4:14:3 | function literal : signature type | semmle.label | function literal : signature type |
13+
| InsecureHostKeyCallbackExample.go:11:20:14:5 | type conversion | semmle.label | type conversion |
14+
| InsecureHostKeyCallbackExample.go:12:4:14:4 | function literal : signature type | semmle.label | function literal : signature type |
1515
| InsecureHostKeyCallbackExample.go:22:20:22:46 | call to InsecureIgnoreHostKey | semmle.label | call to InsecureIgnoreHostKey |
16-
| InsecureHostKeyCallbackExample.go:27:14:30:3 | type conversion : signature type | semmle.label | type conversion : signature type |
17-
| InsecureHostKeyCallbackExample.go:28:3:30:2 | function literal : signature type | semmle.label | function literal : signature type |
16+
| InsecureHostKeyCallbackExample.go:27:14:30:4 | type conversion : signature type | semmle.label | type conversion : signature type |
17+
| InsecureHostKeyCallbackExample.go:28:3:30:3 | function literal : signature type | semmle.label | function literal : signature type |
1818
| InsecureHostKeyCallbackExample.go:35:20:35:27 | callback | semmle.label | callback |
19-
| InsecureHostKeyCallbackExample.go:41:3:43:2 | function literal : signature type | semmle.label | function literal : signature type |
19+
| InsecureHostKeyCallbackExample.go:41:3:43:3 | function literal : signature type | semmle.label | function literal : signature type |
2020
| InsecureHostKeyCallbackExample.go:48:20:48:48 | type conversion | semmle.label | type conversion |
2121
| InsecureHostKeyCallbackExample.go:52:39:52:46 | definition of callback : HostKeyCallback | semmle.label | definition of callback : HostKeyCallback |
2222
| InsecureHostKeyCallbackExample.go:52:39:52:46 | definition of callback : signature type | semmle.label | definition of callback : signature type |
2323
| InsecureHostKeyCallbackExample.go:56:20:56:27 | callback | semmle.label | callback |
24-
| InsecureHostKeyCallbackExample.go:63:22:66:3 | type conversion : signature type | semmle.label | type conversion : signature type |
25-
| InsecureHostKeyCallbackExample.go:64:3:66:2 | function literal : signature type | semmle.label | function literal : signature type |
24+
| InsecureHostKeyCallbackExample.go:63:22:66:4 | type conversion : signature type | semmle.label | type conversion : signature type |
25+
| InsecureHostKeyCallbackExample.go:64:3:66:3 | function literal : signature type | semmle.label | function literal : signature type |
2626
| InsecureHostKeyCallbackExample.go:68:35:68:50 | insecureCallback : signature type | semmle.label | insecureCallback : signature type |
2727
| InsecureHostKeyCallbackExample.go:79:35:79:61 | call to InsecureIgnoreHostKey : HostKeyCallback | semmle.label | call to InsecureIgnoreHostKey : HostKeyCallback |
2828
#select
29-
| InsecureHostKeyCallbackExample.go:11:20:14:4 | type conversion | InsecureHostKeyCallbackExample.go:12:4:14:3 | function literal : signature type | InsecureHostKeyCallbackExample.go:11:20:14:4 | type conversion | Configuring SSH ClientConfig with insecure HostKeyCallback implementation from $@. | InsecureHostKeyCallbackExample.go:12:4:14:3 | function literal | this source |
29+
| InsecureHostKeyCallbackExample.go:11:20:14:5 | type conversion | InsecureHostKeyCallbackExample.go:12:4:14:4 | function literal : signature type | InsecureHostKeyCallbackExample.go:11:20:14:5 | type conversion | Configuring SSH ClientConfig with insecure HostKeyCallback implementation from $@. | InsecureHostKeyCallbackExample.go:12:4:14:4 | function literal | this source |
3030
| InsecureHostKeyCallbackExample.go:22:20:22:46 | call to InsecureIgnoreHostKey | InsecureHostKeyCallbackExample.go:22:20:22:46 | call to InsecureIgnoreHostKey | InsecureHostKeyCallbackExample.go:22:20:22:46 | call to InsecureIgnoreHostKey | Configuring SSH ClientConfig with insecure HostKeyCallback implementation from $@. | InsecureHostKeyCallbackExample.go:22:20:22:46 | call to InsecureIgnoreHostKey | this source |
31-
| InsecureHostKeyCallbackExample.go:35:20:35:27 | callback | InsecureHostKeyCallbackExample.go:28:3:30:2 | function literal : signature type | InsecureHostKeyCallbackExample.go:35:20:35:27 | callback | Configuring SSH ClientConfig with insecure HostKeyCallback implementation from $@. | InsecureHostKeyCallbackExample.go:28:3:30:2 | function literal | this source |
32-
| InsecureHostKeyCallbackExample.go:48:20:48:48 | type conversion | InsecureHostKeyCallbackExample.go:41:3:43:2 | function literal : signature type | InsecureHostKeyCallbackExample.go:48:20:48:48 | type conversion | Configuring SSH ClientConfig with insecure HostKeyCallback implementation from $@. | InsecureHostKeyCallbackExample.go:41:3:43:2 | function literal | this source |
33-
| InsecureHostKeyCallbackExample.go:56:20:56:27 | callback | InsecureHostKeyCallbackExample.go:64:3:66:2 | function literal : signature type | InsecureHostKeyCallbackExample.go:56:20:56:27 | callback | Configuring SSH ClientConfig with insecure HostKeyCallback implementation from $@. | InsecureHostKeyCallbackExample.go:64:3:66:2 | function literal | this source |
31+
| InsecureHostKeyCallbackExample.go:35:20:35:27 | callback | InsecureHostKeyCallbackExample.go:28:3:30:3 | function literal : signature type | InsecureHostKeyCallbackExample.go:35:20:35:27 | callback | Configuring SSH ClientConfig with insecure HostKeyCallback implementation from $@. | InsecureHostKeyCallbackExample.go:28:3:30:3 | function literal | this source |
32+
| InsecureHostKeyCallbackExample.go:48:20:48:48 | type conversion | InsecureHostKeyCallbackExample.go:41:3:43:3 | function literal : signature type | InsecureHostKeyCallbackExample.go:48:20:48:48 | type conversion | Configuring SSH ClientConfig with insecure HostKeyCallback implementation from $@. | InsecureHostKeyCallbackExample.go:41:3:43:3 | function literal | this source |
33+
| InsecureHostKeyCallbackExample.go:56:20:56:27 | callback | InsecureHostKeyCallbackExample.go:64:3:66:3 | function literal : signature type | InsecureHostKeyCallbackExample.go:56:20:56:27 | callback | Configuring SSH ClientConfig with insecure HostKeyCallback implementation from $@. | InsecureHostKeyCallbackExample.go:64:3:66:3 | function literal | this source |
3434
| InsecureHostKeyCallbackExample.go:56:20:56:27 | callback | InsecureHostKeyCallbackExample.go:79:35:79:61 | call to InsecureIgnoreHostKey : HostKeyCallback | InsecureHostKeyCallbackExample.go:56:20:56:27 | callback | Configuring SSH ClientConfig with insecure HostKeyCallback implementation from $@. | InsecureHostKeyCallbackExample.go:79:35:79:61 | call to InsecureIgnoreHostKey | this source |

ql/test/experimental/CWE-322/InsecureHostKeyCallbackExample.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,60 +10,60 @@ func insecureSSHClientConfig() {
1010
Auth: []ssh.AuthMethod{nil},
1111
HostKeyCallback: ssh.HostKeyCallback(
1212
func(hostname string, remote net.Addr, key ssh.PublicKey) error {
13-
return nil
14-
}),
15-
}
13+
return nil
14+
}),
15+
}
1616
}
1717

1818
func insecureSSHClientConfigAlt() {
1919
_ = &ssh.ClientConfig{
20-
User: "user",
21-
Auth: []ssh.AuthMethod{nil},
20+
User: "user",
21+
Auth: []ssh.AuthMethod{nil},
2222
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
23-
}
23+
}
2424
}
2525

2626
func insecureSSHClientConfigLocalFlow() {
2727
callback := ssh.HostKeyCallback(
2828
func(hostname string, remote net.Addr, key ssh.PublicKey) error {
29-
return nil
30-
})
29+
return nil
30+
})
3131

3232
_ = &ssh.ClientConfig{
33-
User: "user",
34-
Auth: []ssh.AuthMethod{nil},
33+
User: "user",
34+
Auth: []ssh.AuthMethod{nil},
3535
HostKeyCallback: callback,
36-
}
36+
}
3737
}
3838

3939
func insecureSSHClientConfigLocalFlowAlt() {
40-
callback :=
40+
callback :=
4141
func(hostname string, remote net.Addr, key ssh.PublicKey) error {
42-
return nil
43-
};
42+
return nil
43+
}
4444

4545
_ = &ssh.ClientConfig{
46-
User: "user",
47-
Auth: []ssh.AuthMethod{nil},
46+
User: "user",
47+
Auth: []ssh.AuthMethod{nil},
4848
HostKeyCallback: ssh.HostKeyCallback(callback),
49-
}
49+
}
5050
}
5151

5252
func potentialInsecureSSHClientConfig(callback ssh.HostKeyCallback) {
5353
_ = &ssh.ClientConfig{
54-
User: "user",
55-
Auth: []ssh.AuthMethod{nil},
54+
User: "user",
55+
Auth: []ssh.AuthMethod{nil},
5656
HostKeyCallback: callback,
57-
}
57+
}
5858
}
5959

6060
func main() {
6161
fmt.Printf("Hello insecure SSH client config!\n")
6262

6363
insecureCallback := ssh.HostKeyCallback(
6464
func(hostname string, remote net.Addr, key ssh.PublicKey) error {
65-
return nil
66-
})
65+
return nil
66+
})
6767

6868
potentialInsecureSSHClientConfig(insecureCallback)
6969

@@ -72,9 +72,9 @@ func main() {
7272
if hostname == "localhost" {
7373
return nil
7474
}
75-
return fmt.Errorf("ssh: Unexpected host for key")
76-
})
75+
return fmt.Errorf("ssh: Unexpected host for key")
76+
})
7777

7878
potentialInsecureSSHClientConfig(potentiallySecureCallback)
7979
potentialInsecureSSHClientConfig(ssh.InsecureIgnoreHostKey())
80-
}
80+
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
| UnreachableStatement.go:5:27:5:29 | increment statement | This statement is unreachable. |
2-
| main.go:11:2:11:14 | expression statement | This statement is unreachable. |
3-
| main.go:16:2:16:14 | expression statement | This statement is unreachable. |
4-
| main.go:20:22:20:34 | expression statement | This statement is unreachable. |
5-
| main.go:28:2:28:14 | expression statement | This statement is unreachable. |
6-
| main.go:47:2:47:14 | expression statement | This statement is unreachable. |
7-
| main.go:53:3:53:15 | expression statement | This statement is unreachable. |
8-
| main.go:55:2:55:14 | expression statement | This statement is unreachable. |
9-
| main.go:139:2:139:26 | return statement | This statement is unreachable. |
10-
| main.go:145:2:145:17 | return statement | This statement is unreachable. |
11-
| main.go:151:2:151:22 | return statement | This statement is unreachable. |
12-
| main.go:157:2:157:43 | return statement | This statement is unreachable. |
2+
| main.go:13:2:13:14 | expression statement | This statement is unreachable. |
3+
| main.go:18:2:18:14 | expression statement | This statement is unreachable. |
4+
| main.go:22:22:22:34 | expression statement | This statement is unreachable. |
5+
| main.go:30:2:30:14 | expression statement | This statement is unreachable. |
6+
| main.go:49:2:49:14 | expression statement | This statement is unreachable. |
7+
| main.go:55:3:55:15 | expression statement | This statement is unreachable. |
8+
| main.go:57:2:57:14 | expression statement | This statement is unreachable. |
9+
| main.go:141:2:141:26 | return statement | This statement is unreachable. |
10+
| main.go:147:2:147:17 | return statement | This statement is unreachable. |
11+
| main.go:153:2:153:22 | return statement | This statement is unreachable. |
12+
| main.go:159:2:159:43 | return statement | This statement is unreachable. |

ql/test/query-tests/RedundantCode/UnreachableStatement/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

3-
import ("errors")
3+
import (
4+
"errors"
5+
)
46

57
func unreachable() {}
68

ql/test/query-tests/Security/CWE-312/klog.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func klogTest() {
2323
klog.Info(mask(name, header)) // OK
2424
}
2525
}
26-
klog.Info(r.Header.Get("Accept")) // OK
27-
klog.Info(r.Header["Content-Type"]) // OK
26+
klog.Info(r.Header.Get("Accept")) // OK
27+
klog.Info(r.Header["Content-Type"]) // OK
2828
klog.Info(r.Header.Get("Authorization")) // NOT OK
2929
})
3030
http.ListenAndServe(":80", nil)

0 commit comments

Comments
 (0)