Skip to content

Commit b6c345b

Browse files
committed
Silence gosec lints
Add one css class escape.
1 parent 5624a9b commit b6c345b

11 files changed

Lines changed: 32 additions & 8 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
run: staticcheck ./...
153153
- name: 'Check: gosec'
154154
if: always()
155-
run: gosec -exclude=G103,G107,G108,G203,G204,G304,G307 -fmt=golint -quiet ./...
155+
run: gosec -fmt=golint -quiet ./...
156156
# The following checks are not dependent on the OS or go build tags. Only
157157
# run them on ubuntu-latest since it's the fastest one.
158158
- name: 'Check: no executable was committed (ubuntu)'

cmd/panic/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func panicRaceDisabled(name string) {
124124
func rerunWithFastCrash() {
125125
if os.Getenv("GORACE") != "log_path=stderr halt_on_error=1" {
126126
_ = os.Setenv("GORACE", "log_path=stderr halt_on_error=1")
127+
/* #nosec G204 */
127128
c := exec.Command(os.Args[0], os.Args[1:]...)
128129
c.Stderr = os.Stderr
129130
if err, ok := c.Run().(*exec.ExitError); ok {

cmd/panicweb/internal/internal.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var Unblock = make(chan struct{})
1818
// GetAsync does an HTTP GET to the URL but leaves the actual fetching to a
1919
// goroutine.
2020
func GetAsync(url string) {
21+
/* #nosec G107 */
2122
resp, err := http.Get(url)
2223
if err != nil {
2324
log.Fatalf("get %s: %v", url, err)

cmd/panicweb/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"log"
2020
"net"
2121
"net/http"
22+
23+
/* #nosec G108 */
2224
_ "net/http/pprof"
2325
"os"
2426
"runtime"

internal/internaltest/internaltest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ func Compile(in, exe, cwd string, disableInlining, race bool) error {
210210
if race {
211211
args = append(args, "-race")
212212
}
213+
/* #nosec G204 */
213214
c := exec.Command("go", append(args, in)...)
214215
c.Dir = cwd
215216
if out, err := c.CombinedOutput(); err != nil {
@@ -231,6 +232,7 @@ func Compile(in, exe, cwd string, disableInlining, race bool) error {
231232
// It ignores the exit code, since it's meant to run panic, which crashes by
232233
// design.
233234
func execRun(cmd ...string) []byte {
235+
/* #nosec G204 */
234236
c := exec.Command(cmd[0], cmd[1:]...)
235237
c.Env = append(os.Environ(), "GOTRACEBACK=all")
236238
out, _ := c.CombinedOutput()

internal/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ type toHTMLer interface {
109109
}
110110

111111
func toHTML(h toHTMLer, p string, needsEnv bool) error {
112+
/* #nosec G304 */
112113
f, err := os.Create(p)
113114
if err != nil {
114115
return err
@@ -290,9 +291,11 @@ func Main() error {
290291
case 1:
291292
// Do not handle SIGQUIT when passed a file to process.
292293
name := flag.Arg(0)
294+
/* #nosec G304 */
293295
if in, err = os.Open(name); err != nil {
294296
return fmt.Errorf("did you mean to specify a valid stack dump file name? %w", err)
295297
}
298+
/* #nosec G307 */
296299
defer in.Close()
297300

298301
default:

internal/main_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func TestProcessTwoSnapshots(t *testing.T) {
102102
if err != nil {
103103
t.Fatal(err)
104104
}
105+
// This is a change detector on main.go.
105106
want := ("Ya\n" +
106107
"GOTRACEBACK=all\n" +
107108
"panic: simple\n\n" +
@@ -112,7 +113,7 @@ func TestProcessTwoSnapshots(t *testing.T) {
112113
"panic: 42\n\n" +
113114
"1: running\n" +
114115
" main main.go:90 panicint(0x2a)\n" +
115-
" main main.go:311 glob..func9()\n" +
116+
" main main.go:312 glob..func9()\n" +
116117
" main main.go:73 main()\n" +
117118
"Yo\n")
118119
compareString(t, want, out.String())

stack/context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,7 @@ func (g *gomodCache) isGoModule(parts []string) (string, string) {
10101010
if runtime.GOOS == "windows" {
10111011
p = strings.Replace(p, "/", pathSeparator, -1)
10121012
}
1013+
/* #nosec G304 */
10131014
b, err := ioutil.ReadFile(p)
10141015
if err != nil {
10151016
continue
@@ -1198,5 +1199,6 @@ func trimCurlyBrackets(s []byte) (int, []byte, int) {
11981199
//
11991200
// A workaround for the absence of https://github.com/golang/go/issues/2632.
12001201
func unsafeString(b []byte) string {
1202+
/* #nosec G103 */
12011203
return *(*string)(unsafe.Pointer(&b))
12021204
}

stack/context_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ func TestScanSnapshotSyntheticTwoSnapshots(t *testing.T) {
13811381
if !s.guessPaths() {
13821382
t.Error("expected success")
13831383
}
1384+
// This is a change detector on internal/main.go.
13841385
want = []*Goroutine{
13851386
{
13861387
Signature: Signature{
@@ -1397,7 +1398,7 @@ func TestScanSnapshotSyntheticTwoSnapshots(t *testing.T) {
13971398
"main.glob..func9",
13981399
Args{},
13991400
pathJoin(ppDir, "main.go"),
1400-
311,
1401+
312,
14011402
),
14021403
newCallLocal(
14031404
"main.main",
@@ -2350,7 +2351,8 @@ func identifyPanicwebSignature(t *testing.T, b *Bucket, pwebDir string) panicweb
23502351
if !b.Signature.Locked {
23512352
t.Fatal("expected Locked")
23522353
}
2353-
want := Stack{Calls: []Call{newCallLocal("main.main", Args{}, pathJoin(pwebDir, "main.go"), 139)}}
2354+
// This is a change detector on internal/main.go.
2355+
want := Stack{Calls: []Call{newCallLocal("main.main", Args{}, pathJoin(pwebDir, "main.go"), 141)}}
23542356
compareStacks(t, &b.Signature.CreatedBy, &want)
23552357
for i := range b.Signature.Stack.Calls {
23562358
if strings.HasPrefix(b.Signature.Stack.Calls[i].ImportPath, "github.com/mattn/go-colorable") {

stack/html.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func funcClass(c *Call) template.HTML {
7272
if c.Func.IsExported {
7373
s += " Exported"
7474
}
75-
return template.HTML("Func" + s)
75+
/* #nosec G203 */
76+
return template.HTML("Func") + template.HTML(template.HTMLEscapeString(s))
7677
}
7778

7879
func minus(i, j int) int {
@@ -107,23 +108,24 @@ func pkgURL(c *Call) template.URL {
107108
}
108109
}
109110
if c.Func.IsExported {
110-
return template.URL(url + ip + "#" + symbol(&c.Func))
111+
return url + ip + template.URL("#") + symbol(&c.Func)
111112
}
112-
return template.URL(url + ip)
113+
return url + ip
113114
}
114115

115116
// srcURL returns an URL to the sources.
116117
//
117118
// TODO(maruel): Support custom local godoc server as it serves files too.
118119
func srcURL(c *Call) template.URL {
119120
url, _ := getSrcBranchURL(c)
120-
return template.URL(url)
121+
return url
121122
}
122123

123124
func escape(s string) template.URL {
124125
// That's the only way I found to get the kind of escaping I wanted, where
125126
// '/' is not escaped.
126127
u := url.URL{Path: s}
128+
/* #nosec G203 */
127129
return template.URL(u.EscapedPath())
128130
}
129131

@@ -140,6 +142,7 @@ func getSrcBranchURL(c *Call) (template.URL, template.URL) {
140142
ver = ver[len(devel) : len(devel)+10]
141143
}
142144
tag = url.QueryEscape(ver)
145+
/* #nosec G203 */
143146
return template.URL(fmt.Sprintf("https://github.com/golang/go/blob/%s/src/%s#L%d", tag, escape(c.RelSrcPath), c.Line)), template.URL(tag)
144147
}
145148
// TODO(maruel): Leverage Location.
@@ -156,6 +159,7 @@ func getSrcBranchURL(c *Call) (template.URL, template.URL) {
156159
if parts := strings.SplitN(rest, "/", 3); len(parts) == 3 {
157160
p, srcTag, tag := splitTag(parts[1])
158161
url := fmt.Sprintf("https://github.com/%s/%s/blob/%s/%s#L%d", escape(parts[0]), p, srcTag, escape(parts[2]), c.Line)
162+
/* #nosec G203 */
159163
return template.URL(url), tag
160164
}
161165
log.Printf("problematic github.com URL: %q", rel)
@@ -168,6 +172,7 @@ func getSrcBranchURL(c *Call) (template.URL, template.URL) {
168172
// The source of truth is are actually go.googlesource.com, but
169173
// github.com has nicer syntax highlighting.
170174
url := fmt.Sprintf("https://github.com/golang/%s/blob/%s/%s#L%d", p, srcTag, escape(parts[2]), c.Line)
175+
/* #nosec G203 */
171176
return template.URL(url), tag
172177
}
173178
log.Printf("problematic golang.org URL: %q", rel)
@@ -185,9 +190,11 @@ func getSrcBranchURL(c *Call) (template.URL, template.URL) {
185190
}
186191

187192
if c.LocalSrcPath != "" {
193+
/* #nosec G203 */
188194
return template.URL("file:///" + escape(c.LocalSrcPath)), template.URL(tag)
189195
}
190196
if c.RemoteSrcPath != "" {
197+
/* #nosec G203 */
191198
return template.URL("file:///" + escape(c.RemoteSrcPath)), template.URL(tag)
192199
}
193200
return "", ""
@@ -219,6 +226,7 @@ func splitTag(s string) (string, string, template.URL) {
219226
if m := reVersion.FindStringSubmatch(tag); len(m) != 0 {
220227
srcTag = m[1]
221228
}
229+
/* #nosec G203 */
222230
return s[:i], url.QueryEscape(srcTag), template.URL(url.QueryEscape(tag))
223231
}
224232

@@ -233,5 +241,6 @@ func symbol(f *Func) template.URL {
233241
// Transform the method form.
234242
s = reMethodSymbol.ReplaceAllString(s, "$1$2")
235243
}
244+
/* #nosec G203 */
236245
return template.URL(url.QueryEscape(s))
237246
}

0 commit comments

Comments
 (0)