Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ autoformat:
find . -path '**/vendor' -prune -or -type f -iname '*.go' ! -empty -print0 | xargs -0 grep -L "//\s*autoformat-ignore" | xargs gofmt -w

check-formatting:
test -z "$$(find . -path '**/vendor' -prune -or -type f -iname '*.go' ! -empty -print0 | xargs -0 grep -L "//\s*autoformat-ignore" | xargs gofmt -l)"
@output=$$(find . -path '**/vendor' -prune -or -type f -iname '*.go' ! -empty -print0 | xargs -0 grep -L "//\s*autoformat-ignore" | xargs gofmt -l 2>&1); \
if [ -n "$$output" ]; then \
echo "The following files need to be reformatted using gofmt or have compilation errors:"; \
echo "$$output"; \
fi; \
test -z "$$output"

ifeq ($(QHELP_OUT_DIR),)
# If not otherwise specified, compile qhelp to markdown in place
Expand Down
11 changes: 9 additions & 2 deletions go/ql/src/experimental/CWE-203/timingBad.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
func bad(w http.ResponseWriter, req *http.Request, []byte secret) (interface{}, error) {
package main

import (
"fmt"
"net/http"
)

func bad(w http.ResponseWriter, req *http.Request, secret []byte) (interface{}, error) {

secretHeader := "X-Secret"

Expand All @@ -8,4 +15,4 @@ func bad(w http.ResponseWriter, req *http.Request, []byte secret) (interface{},
return nil, fmt.Errorf("header %s=%s did not match expected secret", secretHeader, headerSecret)
}
return nil, nil
}
}
12 changes: 10 additions & 2 deletions go/ql/src/experimental/CWE-203/timingGood.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
func good(w http.ResponseWriter, req *http.Request, []byte secret) (interface{}, error) {
package main

import (
"crypto/subtle"
"fmt"
"net/http"
)

func good(w http.ResponseWriter, req *http.Request, secret []byte) (interface{}, error) {

secretHeader := "X-Secret"

Expand All @@ -7,4 +15,4 @@ func good(w http.ResponseWriter, req *http.Request, []byte secret) (interface{},
return nil, fmt.Errorf("header %s=%s did not match expected secret", secretHeader, headerSecret)
}
return nil, nil
}
}
7 changes: 7 additions & 0 deletions go/ql/src/experimental/CWE-74/DsnBad.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
package main

import (
"database/sql"
"fmt"
"os"
)

func bad() interface{} {
name := os.Args[1:]
Expand Down
10 changes: 10 additions & 0 deletions go/ql/src/experimental/CWE-74/DsnGood.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
package main

import (
"database/sql"
"errors"
"fmt"
"os"
"regexp"
)

func good() (interface{}, error) {
name := os.Args[1]
hasBadChar, _ := regexp.MatchString(".*[?].*", name)
Expand Down