aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dashboard/app/jobs.go5
-rw-r--r--dashboard/app/kcidb.go9
-rw-r--r--dashboard/app/main.go6
-rw-r--r--dashboard/app/reporting.go5
-rw-r--r--dashboard/app/util_test.go5
-rw-r--r--pkg/bisect/bisect.go5
-rw-r--r--pkg/build/build.go15
-rw-r--r--pkg/compiler/check.go17
-rw-r--r--pkg/csource/common.go8
-rw-r--r--pkg/csource/csource.go14
-rw-r--r--pkg/csource/options.go6
-rw-r--r--pkg/declextract/declextract.go4
-rw-r--r--pkg/email/parser.go4
-rw-r--r--pkg/email/parser_test.go6
-rw-r--r--pkg/ifuzz/powerpc/pseudo.go5
-rw-r--r--pkg/ifuzz/x86/decode.go12
-rw-r--r--pkg/ifuzz/x86/encode.go36
-rw-r--r--pkg/kcidb/client.go2
-rw-r--r--pkg/kconfig/kconfig.go8
-rw-r--r--pkg/report/report.go8
-rw-r--r--pkg/runtest/run.go4
-rw-r--r--pkg/symbolizer/addr2line.go6
-rw-r--r--pkg/vcs/linux.go12
-rw-r--r--prog/any.go5
-rw-r--r--prog/meta.go2
-rw-r--r--prog/minimization_test.go7
-rw-r--r--sys/openbsd/init.go7
-rw-r--r--sys/targets/targets.go4
-rw-r--r--syz-ci/jobs.go6
-rw-r--r--syz-ci/jobs_test.go2
-rw-r--r--syz-ci/manager.go2
-rw-r--r--syz-ci/syz-ci.go4
-rw-r--r--syz-cluster/pkg/emailclient/sender.go5
-rw-r--r--syz-hub/http.go2
-rw-r--r--syz-manager/manager.go14
-rw-r--r--tools/syz-check/check.go2
-rw-r--r--vm/proxyapp/proxyappclient.go4
-rw-r--r--vm/qemu/qemu.go2
38 files changed, 144 insertions, 126 deletions
diff --git a/dashboard/app/jobs.go b/dashboard/app/jobs.go
index f5f629d81..b7ff881a3 100644
--- a/dashboard/app/jobs.go
+++ b/dashboard/app/jobs.go
@@ -940,10 +940,11 @@ func handleRetestedRepro(c context.Context, now time.Time, job *Job, jobKey *db.
crash.LastReproRetest = now
if req.Error == nil && !crash.ReproIsRevoked {
// If repro testing itself failed, it might be just a temporary issue.
- if job.Type == JobTestPatch {
+ switch job.Type {
+ case JobTestPatch:
// If there was any crash at all, the repro is still not worth discarding.
crash.ReproIsRevoked = len(allTitles) == 0
- } else if job.Type == JobBisectFix {
+ case JobBisectFix:
// More than one commit is suspected => repro stopped working at some point.
crash.ReproIsRevoked = len(req.Commits) > 0
}
diff --git a/dashboard/app/kcidb.go b/dashboard/app/kcidb.go
index 6fe641276..7203c6dfa 100644
--- a/dashboard/app/kcidb.go
+++ b/dashboard/app/kcidb.go
@@ -69,13 +69,8 @@ func publishKcidbBug(c context.Context, client *kcidb.Client, bug *Bug, bugKey *
if err != nil {
return false, err
}
- publish := true
- if rep.KernelCommit == "" || len(rep.KernelConfig) == 0 {
- // This should happen only for syzkaller build/test errors, which we don't want to publish.
- // But if this ever happens for a kernel bug, then we also don't want to publish such bugs
- // with missing critical info.
- publish = false
- }
+ publish := !(rep.KernelCommit == "" || len(rep.KernelConfig) == 0)
+
if publish {
if err := client.Publish(rep); err != nil {
return false, err
diff --git a/dashboard/app/main.go b/dashboard/app/main.go
index 78aed619f..eeba85c9e 100644
--- a/dashboard/app/main.go
+++ b/dashboard/app/main.go
@@ -1315,7 +1315,7 @@ func debugBugSubsystems(c context.Context, w http.ResponseWriter, bug *Bug) erro
TraceWriter: w,
})
if err != nil {
- w.Write([]byte(fmt.Sprintf("%s", err)))
+ fmt.Fprintf(w, "%s", err)
}
return nil
}
@@ -2407,8 +2407,8 @@ func invalidateJobLink(c context.Context, job *Job, jobKey *db.Key, restart bool
func formatLogLine(line string) string {
const maxLineLen = 1000
- line = strings.Replace(line, "\n", " ", -1)
- line = strings.Replace(line, "\r", "", -1)
+ line = strings.ReplaceAll(line, "\n", " ")
+ line = strings.ReplaceAll(line, "\r", "")
if len(line) > maxLineLen {
line = line[:maxLineLen]
line += "..."
diff --git a/dashboard/app/reporting.go b/dashboard/app/reporting.go
index b73bab8ac..c5e6ff1e3 100644
--- a/dashboard/app/reporting.go
+++ b/dashboard/app/reporting.go
@@ -1288,11 +1288,12 @@ func findCrashForBug(c context.Context, bug *Bug) (*Crash, *db.Key, error) {
return nil, nil, fmt.Errorf("no crashes")
}
crash, key := crashes[0], keys[0]
- if bug.HeadReproLevel == ReproLevelC {
+ switch bug.HeadReproLevel {
+ case ReproLevelC:
if crash.ReproC == 0 {
log.Errorf(c, "bug '%v': has C repro, but crash without C repro", bug.Title)
}
- } else if bug.HeadReproLevel == ReproLevelSyz {
+ case ReproLevelSyz:
if crash.ReproSyz == 0 {
log.Errorf(c, "bug '%v': has syz repro, but crash without syz repro", bug.Title)
}
diff --git a/dashboard/app/util_test.go b/dashboard/app/util_test.go
index f9e2ad660..2040f879e 100644
--- a/dashboard/app/util_test.go
+++ b/dashboard/app/util_test.go
@@ -357,9 +357,10 @@ func (c *Ctx) httpRequest(method, url, body, contentType string,
}
r = registerRequest(r, c)
r = r.WithContext(c.transformContext(r.Context()))
- if access == AccessAdmin {
+ switch access {
+ case AccessAdmin:
aetest.Login(makeUser(AuthorizedAdmin), r)
- } else if access == AccessUser {
+ case AccessUser:
aetest.Login(makeUser(AuthorizedUser), r)
}
w := httptest.NewRecorder()
diff --git a/pkg/bisect/bisect.go b/pkg/bisect/bisect.go
index ba022e514..c4b2ebf50 100644
--- a/pkg/bisect/bisect.go
+++ b/pkg/bisect/bisect.go
@@ -749,9 +749,10 @@ func (env *env) testPredicate() (vcs.BisectResult, error) {
}
// For fix bisections, results are inverted.
if env.cfg.Fix {
- if testRes1.verdict == vcs.BisectBad {
+ switch testRes1.verdict {
+ case vcs.BisectBad:
testRes1.verdict = vcs.BisectGood
- } else if testRes1.verdict == vcs.BisectGood {
+ case vcs.BisectGood:
testRes1.verdict = vcs.BisectBad
}
}
diff --git a/pkg/build/build.go b/pkg/build/build.go
index 86906a0f7..26ba8f4d3 100644
--- a/pkg/build/build.go
+++ b/pkg/build/build.go
@@ -156,13 +156,14 @@ type builder interface {
func getBuilder(targetOS, targetArch, vmType string) (builder, error) {
if targetOS == targets.Linux {
- if vmType == targets.GVisor {
+ switch vmType {
+ case targets.GVisor:
return gvisor{}, nil
- } else if vmType == "cuttlefish" {
+ case "cuttlefish":
return cuttlefish{}, nil
- } else if vmType == "proxyapp:android" {
+ case "proxyapp:android":
return android{}, nil
- } else if vmType == targets.Starnix {
+ case targets.Starnix:
return starnix{}, nil
}
}
@@ -266,7 +267,7 @@ func extractCauseInner(s []byte, kernelSrc string) ([]byte, string) {
file := ""
for i := range lines {
if stripPrefix != nil {
- lines[i] = bytes.Replace(lines[i], stripPrefix, nil, -1)
+ lines[i] = bytes.ReplaceAll(lines[i], stripPrefix, nil)
}
if file == "" {
for _, fileRe := range fileRes {
@@ -292,8 +293,8 @@ func extractCauseInner(s []byte, kernelSrc string) ([]byte, string) {
res := bytes.Join(lines, []byte{'\n'})
// gcc uses these weird quotes around identifiers, which may be
// mis-rendered by systems that don't understand utf-8.
- res = bytes.Replace(res, []byte("‘"), []byte{'\''}, -1)
- res = bytes.Replace(res, []byte("’"), []byte{'\''}, -1)
+ res = bytes.ReplaceAll(res, []byte("‘"), []byte{'\''})
+ res = bytes.ReplaceAll(res, []byte("’"), []byte{'\''})
return res, file
}
diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go
index bd3489ccc..121e7386a 100644
--- a/pkg/compiler/check.go
+++ b/pkg/compiler/check.go
@@ -393,7 +393,8 @@ func (comp *compiler) checkRequiredCallAttrs(call *ast.Call, callAttrNames map[s
}
}
- if desc == typeStruct {
+ switch desc {
+ case typeStruct:
s := comp.structs[t.Ident]
// Prune recursion, can happen even on correct tree via opt pointers.
if checked[s.Name.Name] {
@@ -404,10 +405,10 @@ func (comp *compiler) checkRequiredCallAttrs(call *ast.Call, callAttrNames map[s
for _, fld := range fields {
comp.checkRequiredCallAttrs(call, callAttrNames, fld.Type, checked)
}
- } else if desc == typeArray {
+ case typeArray:
typ := t.Args[0]
comp.checkRequiredCallAttrs(call, callAttrNames, typ, checked)
- } else if desc == typePtr {
+ case typePtr:
typ := t.Args[1]
comp.checkRequiredCallAttrs(call, callAttrNames, typ, checked)
}
@@ -502,9 +503,10 @@ func (comp *compiler) checkFieldPathsRec(t0, t *ast.Type, parents []parentDesc,
_, args, _ := comp.getArgsBase(t, isArg)
for i, arg := range args {
argDesc := desc.Args[i]
- if argDesc.Type == typeArgLenTarget {
+ switch argDesc.Type {
+ case typeArgLenTarget:
comp.validateFieldPath(arg, t0, t, parents, warned)
- } else if argDesc.Type == typeArgType {
+ case typeArgType:
comp.checkFieldPathsRec(t0, arg, parents, checked, warned, argDesc.IsArg)
}
}
@@ -1548,13 +1550,14 @@ func (comp *compiler) checkDupConstsCall(n *ast.Call, dups map[string]map[string
constArgID := ""
for i, arg := range n.Args {
desc := comp.getTypeDesc(arg.Type)
- if desc == typeConst {
+ switch desc {
+ case typeConst:
v := arg.Type.Args[0].Value
if v != 0 && v != 18446744073709551516 { // AT_FDCWD
constArgID += fmt.Sprintf("(%v-%v)", i, fmt.Sprintf("%v", v))
hasConsts = true
}
- } else if desc == typeResource {
+ case typeResource:
constArgID += fmt.Sprintf("(%v-%v)", i, arg.Type.Ident)
}
}
diff --git a/pkg/csource/common.go b/pkg/csource/common.go
index a065a6bdb..f71926659 100644
--- a/pkg/csource/common.go
+++ b/pkg/csource/common.go
@@ -56,7 +56,7 @@ func createCommonHeader(p, mmapProg *prog.Prog, replacements map[string]string,
}
for from, to := range replacements {
- src = bytes.Replace(src, []byte("/*{{{"+from+"}}}*/"), []byte(to), -1)
+ src = bytes.ReplaceAll(src, []byte("/*{{{"+from+"}}}*/"), []byte(to))
}
for from, to := range map[string]string{
@@ -65,7 +65,7 @@ func createCommonHeader(p, mmapProg *prog.Prog, replacements map[string]string,
"uint16": "uint16_t",
"uint8": "uint8_t",
} {
- src = bytes.Replace(src, []byte(from), []byte(to), -1)
+ src = bytes.ReplaceAll(src, []byte(from), []byte(to))
}
src = regexp.MustCompile("#define SYZ_HAVE_.*").ReplaceAll(src, nil)
@@ -149,7 +149,7 @@ func removeSystemDefines(src []byte, defines []string) ([]byte, error) {
}
}
for def, val := range remove {
- src = bytes.Replace(src, []byte("#define "+def+" "+val+"\n"), nil, -1)
+ src = bytes.ReplaceAll(src, []byte("#define "+def+" "+val+"\n"), nil)
}
// strip: #define __STDC_VERSION__ 201112L
for _, def := range []string{"__STDC_VERSION__"} {
@@ -161,7 +161,7 @@ func removeSystemDefines(src []byte, defines []string) ([]byte, error) {
if end == -1 {
continue
}
- src = bytes.Replace(src, src[pos:end+1], nil, -1)
+ src = bytes.ReplaceAll(src, src[pos:end+1], nil)
}
return src, nil
}
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go
index d5da107b0..a37040e8f 100644
--- a/pkg/csource/csource.go
+++ b/pkg/csource/csource.go
@@ -202,7 +202,7 @@ func (ctx *context) generateSyscalls(calls []string, hasVars bool) string {
fmt.Fprintf(buf, "\tswitch (call) {\n")
for i, c := range calls {
fmt.Fprintf(buf, "\tcase %v:\n", i)
- fmt.Fprintf(buf, "%s", strings.Replace(c, "\t", "\t\t", -1))
+ fmt.Fprintf(buf, "%s", strings.ReplaceAll(c, "\t", "\t\t"))
fmt.Fprintf(buf, "\t\tbreak;\n")
}
fmt.Fprintf(buf, "\t}\n")
@@ -627,10 +627,10 @@ func (ctx *context) postProcess(result []byte) []byte {
if !ctx.opts.HandleSegv {
result = regexp.MustCompile(`\t*NONFAILING\((.*)\);\n`).ReplaceAll(result, []byte("$1;\n"))
}
- result = bytes.Replace(result, []byte("NORETURN"), nil, -1)
- result = bytes.Replace(result, []byte("doexit("), []byte("exit("), -1)
+ result = bytes.ReplaceAll(result, []byte("NORETURN"), nil)
+ result = bytes.ReplaceAll(result, []byte("doexit("), []byte("exit("))
// TODO: Figure out what would be the right replacement for doexit_thread().
- result = bytes.Replace(result, []byte("doexit_thread("), []byte("exit("), -1)
+ result = bytes.ReplaceAll(result, []byte("doexit_thread("), []byte("exit("))
result = regexp.MustCompile(`PRINTF\(.*?\)`).ReplaceAll(result, nil)
result = regexp.MustCompile(`\t*debug\((.*\n)*?.*\);\n`).ReplaceAll(result, nil)
result = regexp.MustCompile(`\t*debug_dump_data\((.*\n)*?.*\);\n`).ReplaceAll(result, nil)
@@ -683,9 +683,9 @@ func (ctx *context) hoistIncludes(result []byte) []byte {
// removeEmptyLines removes duplicate new lines.
func (ctx *context) removeEmptyLines(result []byte) []byte {
for {
- newResult := bytes.Replace(result, []byte{'\n', '\n', '\n'}, []byte{'\n', '\n'}, -1)
- newResult = bytes.Replace(newResult, []byte{'\n', '\n', '\t'}, []byte{'\n', '\t'}, -1)
- newResult = bytes.Replace(newResult, []byte{'\n', '\n', ' '}, []byte{'\n', ' '}, -1)
+ newResult := bytes.ReplaceAll(result, []byte{'\n', '\n', '\n'}, []byte{'\n', '\n'})
+ newResult = bytes.ReplaceAll(newResult, []byte{'\n', '\n', '\t'}, []byte{'\n', '\t'})
+ newResult = bytes.ReplaceAll(newResult, []byte{'\n', '\n', ' '}, []byte{'\n', ' '})
if len(newResult) == len(result) {
return result
}
diff --git a/pkg/csource/options.go b/pkg/csource/options.go
index ba44dd021..02e39980a 100644
--- a/pkg/csource/options.go
+++ b/pkg/csource/options.go
@@ -125,11 +125,11 @@ func (opts Options) checkLinuxOnly(OS string) error {
if OS == targets.Linux {
return nil
}
- if opts.NetInjection && !(OS == targets.OpenBSD || OS == targets.FreeBSD || OS == targets.NetBSD) {
+ if opts.NetInjection && (OS != targets.OpenBSD && OS != targets.FreeBSD && OS != targets.NetBSD) {
return fmt.Errorf("option NetInjection is not supported on %v", OS)
}
if opts.Sandbox == sandboxNamespace ||
- (opts.Sandbox == sandboxSetuid && !(OS == targets.OpenBSD || OS == targets.FreeBSD || OS == targets.NetBSD)) ||
+ (opts.Sandbox == sandboxSetuid && (OS != targets.OpenBSD && OS != targets.FreeBSD && OS != targets.NetBSD)) ||
opts.Sandbox == sandboxAndroid {
return fmt.Errorf("option Sandbox=%v is not supported on %v", opts.Sandbox, OS)
}
@@ -248,7 +248,7 @@ func deserializeLegacyOptions(data string, opts *Options) (int, error) {
// Support for legacy formats.
func deserializeLegacyFormats(data []byte, opts *Options) error {
- data = bytes.Replace(data, []byte("Sandbox: "), []byte("Sandbox:empty "), -1)
+ data = bytes.ReplaceAll(data, []byte("Sandbox: "), []byte("Sandbox:empty "))
strData := string(data)
// We can distinguish between legacy formats by the number
diff --git a/pkg/declextract/declextract.go b/pkg/declextract/declextract.go
index 7320279bc..923e2440f 100644
--- a/pkg/declextract/declextract.go
+++ b/pkg/declextract/declextract.go
@@ -419,8 +419,8 @@ func (ctx *context) specialInt4(field, typ string, needBase bool) string {
}
func (ctx *context) specialIntptr(field, typ string, needBase bool) string {
- switch {
- case field == "sigsetsize":
+ switch field {
+ case "sigsetsize":
return fmt.Sprintf("const[8 %v]", maybeBaseType("intptr", needBase))
}
return ""
diff --git a/pkg/email/parser.go b/pkg/email/parser.go
index 3ebd7ac08..6db3d2415 100644
--- a/pkg/email/parser.go
+++ b/pkg/email/parser.go
@@ -368,9 +368,9 @@ func extractArgsTokens(body string, num int) string {
if lineEnd == -1 {
lineEnd = len(body) - pos
}
- line := strings.TrimSpace(strings.Replace(body[pos:pos+lineEnd], "\t", " ", -1))
+ line := strings.TrimSpace(strings.ReplaceAll(body[pos:pos+lineEnd], "\t", " "))
for {
- line1 := strings.Replace(line, " ", " ", -1)
+ line1 := strings.ReplaceAll(line, " ", " ")
if line == line1 {
break
}
diff --git a/pkg/email/parser_test.go b/pkg/email/parser_test.go
index 87f6ec38e..c9e7022ae 100644
--- a/pkg/email/parser_test.go
+++ b/pkg/email/parser_test.go
@@ -19,7 +19,7 @@ func TestExtractCommand(t *testing.T) {
if diff := cmp.Diff(test.cmd, cmd); diff != "" {
t.Fatal(diff)
}
- cmd, _ = extractCommand(strings.Replace(test.body, "\n", "\r\n", -1))
+ cmd, _ = extractCommand(strings.ReplaceAll(test.body, "\n", "\r\n"))
if diff := cmp.Diff(test.cmd, cmd); diff != "" {
t.Fatal(diff)
}
@@ -130,8 +130,8 @@ func TestParse(t *testing.T) {
}
t.Run(fmt.Sprint(i), func(t *testing.T) { body(t, test) })
- test.email = strings.Replace(test.email, "\n", "\r\n", -1)
- test.res.Body = strings.Replace(test.res.Body, "\n", "\r\n", -1)
+ test.email = strings.ReplaceAll(test.email, "\n", "\r\n")
+ test.res.Body = strings.ReplaceAll(test.res.Body, "\n", "\r\n")
t.Run(fmt.Sprint(i)+"rn", func(t *testing.T) { body(t, test) })
}
}
diff --git a/pkg/ifuzz/powerpc/pseudo.go b/pkg/ifuzz/powerpc/pseudo.go
index f67a38907..fcc7b0941 100644
--- a/pkg/ifuzz/powerpc/pseudo.go
+++ b/pkg/ifuzz/powerpc/pseudo.go
@@ -96,10 +96,11 @@ func (gen *generator) sc(lev uint) {
hcrange := gen.r.Intn(3)
offset := 4
maxhc := MaxHcall
- if hcrange == 1 {
+ switch hcrange {
+ case 1:
offset = 0xf000
maxhc = 0xf810
- } else if hcrange == 2 {
+ case 2:
offset = 0xef00
maxhc = 0xef20
}
diff --git a/pkg/ifuzz/x86/decode.go b/pkg/ifuzz/x86/decode.go
index 0160e0fd3..dd9418e07 100644
--- a/pkg/ifuzz/x86/decode.go
+++ b/pkg/ifuzz/x86/decode.go
@@ -65,20 +65,22 @@ func (insnset *InsnSet) Decode(mode iset.Mode, text []byte) (int, error) {
for len(text) != 0 && prefixes[text[0]] {
switch text[0] {
case 0x66:
- if immSize == 4 {
+ switch immSize {
+ case 4:
immSize1 = 2
operSize1 = 2
- } else if immSize == 2 {
+ case 2:
immSize1 = 4
operSize1 = 4
}
case 0x67:
- if addrSize == 8 {
+ switch addrSize {
+ case 8:
addrSize1 = 4
- } else if addrSize == 4 {
+ case 4:
dispSize1 = 2
addrSize1 = 2
- } else if addrSize == 2 {
+ case 2:
dispSize1 = 4
addrSize1 = 4
}
diff --git a/pkg/ifuzz/x86/encode.go b/pkg/ifuzz/x86/encode.go
index 59b9a294a..b196e81b2 100644
--- a/pkg/ifuzz/x86/encode.go
+++ b/pkg/ifuzz/x86/encode.go
@@ -90,20 +90,22 @@ func (insn *Insn) Encode(cfg *iset.Config, r *rand.Rand) []byte {
for _, pref := range code {
switch pref {
case 0x66:
- if immSize == 4 {
+ switch immSize {
+ case 4:
immSize1 = 2
operSize1 = 2
- } else if immSize == 2 {
+ case 2:
immSize1 = 4
operSize1 = 4
}
case 0x67:
- if addrSize == 8 {
+ switch addrSize {
+ case 8:
addrSize1 = 4
- } else if addrSize == 4 {
+ case 4:
dispSize1 = 2
addrSize1 = 2
- } else if addrSize == 2 {
+ case 2:
dispSize1 = 4
addrSize1 = 4
}
@@ -125,15 +127,17 @@ func (insn *Insn) Encode(cfg *iset.Config, r *rand.Rand) []byte {
}
vexB = byte(r.Intn(2))
W := byte(r.Intn(2))
- if insn.Rexw == 1 {
+ switch insn.Rexw {
+ case 1:
W = 1
- } else if insn.Rexw == -1 {
+ case -1:
W = 0
}
L := byte(r.Intn(2))
- if insn.VexL == 1 {
+ switch insn.VexL {
+ case 1:
L = 1
- } else if insn.VexL == -1 {
+ case -1:
L = 0
}
pp := byte(r.Intn(4))
@@ -174,11 +178,12 @@ func (insn *Insn) Encode(cfg *iset.Config, r *rand.Rand) []byte {
}
reg := byte(insn.Reg)
- if insn.Reg == -1 {
+ switch insn.Reg {
+ case -1:
reg = byte(r.Intn(8))
- } else if insn.Reg == -6 {
+ case -6:
reg = byte(r.Intn(6)) // segment register
- } else if insn.Reg == -8 {
+ case -8:
if rexR {
reg = 0 // CR8
} else {
@@ -242,11 +247,12 @@ func (insn *Insn) Encode(cfg *iset.Config, r *rand.Rand) []byte {
}
addImm := func(imm int) {
- if imm == -1 {
+ switch imm {
+ case -1:
imm = immSize
- } else if imm == -2 {
+ case -2:
imm = addrSize
- } else if imm == -3 {
+ case -3:
imm = operSize
}
if imm != 0 {
diff --git a/pkg/kcidb/client.go b/pkg/kcidb/client.go
index 1c4d53764..687386f37 100644
--- a/pkg/kcidb/client.go
+++ b/pkg/kcidb/client.go
@@ -178,7 +178,7 @@ func normalizeRepo(repo string) string {
// and where it isn't. We know that "https:" is supported on kernel.org,
// and that's the main case we need to fix up. "https:" is always used
// for github.com and googlesource.com.
- return strings.Replace(repo, "git://git.kernel.org", "https://git.kernel.org", -1)
+ return strings.ReplaceAll(repo, "git://git.kernel.org", "https://git.kernel.org")
}
func (c *Client) extID(id string) string {
diff --git a/pkg/kconfig/kconfig.go b/pkg/kconfig/kconfig.go
index 7cb54a1bb..15dc0d22a 100644
--- a/pkg/kconfig/kconfig.go
+++ b/pkg/kconfig/kconfig.go
@@ -449,9 +449,9 @@ func (kp *kconfigParser) parseDefaultValue() {
}
func (kp *kconfigParser) expandString(str string) string {
- str = strings.Replace(str, "$(SRCARCH)", kp.target.KernelHeaderArch, -1)
- str = strings.Replace(str, "$SRCARCH", kp.target.KernelHeaderArch, -1)
- str = strings.Replace(str, "$(KCONFIG_EXT_PREFIX)", "", -1)
- str = strings.Replace(str, "$(MALI_KCONFIG_EXT_PREFIX)", "", -1) // ChromeOS.
+ str = strings.ReplaceAll(str, "$(SRCARCH)", kp.target.KernelHeaderArch)
+ str = strings.ReplaceAll(str, "$SRCARCH", kp.target.KernelHeaderArch)
+ str = strings.ReplaceAll(str, "$(KCONFIG_EXT_PREFIX)", "")
+ str = strings.ReplaceAll(str, "$(MALI_KCONFIG_EXT_PREFIX)", "") // ChromeOS.
return str
}
diff --git a/pkg/report/report.go b/pkg/report/report.go
index 44d4563e2..2ac039fdd 100644
--- a/pkg/report/report.go
+++ b/pkg/report/report.go
@@ -438,10 +438,10 @@ type frameExtractor func(frames []string) (string, int)
var parseStackTrace *regexp.Regexp
func compile(re string) *regexp.Regexp {
- re = strings.Replace(re, "{{ADDR}}", "0x[0-9a-f]+", -1)
- re = strings.Replace(re, "{{PC}}", "\\[\\<?(?:0x)?[0-9a-f]+\\>?\\]", -1)
- re = strings.Replace(re, "{{FUNC}}", "([a-zA-Z0-9_]+)(?:\\.|\\+)", -1)
- re = strings.Replace(re, "{{SRC}}", "([a-zA-Z0-9-_/.]+\\.[a-z]+:[0-9]+)", -1)
+ re = strings.ReplaceAll(re, "{{ADDR}}", "0x[0-9a-f]+")
+ re = strings.ReplaceAll(re, "{{PC}}", "\\[\\<?(?:0x)?[0-9a-f]+\\>?\\]")
+ re = strings.ReplaceAll(re, "{{FUNC}}", "([a-zA-Z0-9_]+)(?:\\.|\\+)")
+ re = strings.ReplaceAll(re, "{{SRC}}", "([a-zA-Z0-9-_/.]+\\.[a-z]+:[0-9]+)")
return regexp.MustCompile(re)
}
diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go
index e95a1aa38..36159b9a7 100644
--- a/pkg/runtest/run.go
+++ b/pkg/runtest/run.go
@@ -100,10 +100,10 @@ func (ctx *Context) Run(waitCtx context.Context) error {
if req.err != nil {
fail++
result = fmt.Sprintf("FAIL: %v",
- strings.Replace(req.err.Error(), "\n", "\n\t", -1))
+ strings.ReplaceAll(req.err.Error(), "\n", "\n\t"))
if req.result != nil && len(req.result.Output) != 0 {
result += fmt.Sprintf("\n\t%s",
- strings.Replace(string(req.result.Output), "\n", "\n\t", -1))
+ strings.ReplaceAll(string(req.result.Output), "\n", "\n\t"))
}
} else {
ok++
diff --git a/pkg/symbolizer/addr2line.go b/pkg/symbolizer/addr2line.go
index bb4e4a3fa..35cbfbe98 100644
--- a/pkg/symbolizer/addr2line.go
+++ b/pkg/symbolizer/addr2line.go
@@ -136,10 +136,8 @@ func parse(interner *Interner, s *bufio.Scanner) ([]Frame, error) {
return nil, fmt.Errorf("failed to parse pc '%v' in addr2line output: %w", s.Text(), err)
}
var frames []Frame
- for {
- if !s.Scan() {
- break
- }
+ for s.Scan() {
+
ln := s.Text()
if len(ln) > 3 && ln[0] == '0' && ln[1] == 'x' {
break
diff --git a/pkg/vcs/linux.go b/pkg/vcs/linux.go
index e34fe9186..f1e73a265 100644
--- a/pkg/vcs/linux.go
+++ b/pkg/vcs/linux.go
@@ -50,7 +50,8 @@ func (ctx *linux) PreviousReleaseTags(commit, compilerType string) ([]string, er
}
cutoff := ""
- if compilerType == "gcc" {
+ switch compilerType {
+ case "gcc":
// Initially we tried to stop at 3.8 because:
// v3.8 does not work with modern perl, and as we go further in history
// make stops to work, then binutils, glibc, etc. So we stop at v3.8.
@@ -75,7 +76,7 @@ func (ctx *linux) PreviousReleaseTags(commit, compilerType string) ([]string, er
// This has caused lots of bad bisection results, see #3224. We either need a new
// universal image or a kernel version dependant image selection.
cutoff = "v4.18"
- } else if compilerType == "clang" {
+ case "clang":
// v5.3 was the first release with solid clang support, however I was able to
// compile v5.1..v5.3 using a newer defconfig + make oldconfig. Everything older
// would require further cherry-picks.
@@ -139,11 +140,12 @@ func (ctx *linux) EnvForCommit(
setLinuxTagConfigs(cf, tags)
compiler := ""
- if compilerType == "gcc" {
+ switch compilerType {
+ case "gcc":
compiler = linuxGCCPath(tags, binDir, defaultCompiler)
- } else if compilerType == "clang" {
+ case "clang":
compiler = linuxClangPath(tags, binDir, defaultCompiler)
- } else {
+ default:
return nil, fmt.Errorf("unsupported bisect compiler: %v", compilerType)
}
diff --git a/prog/any.go b/prog/any.go
index cb49f3494..3969a5386 100644
--- a/prog/any.go
+++ b/prog/any.go
@@ -49,9 +49,10 @@ func (target *Target) initAnyTypes() {
}
func (target *Target) getAnyPtrType(size uint64) *PtrType {
- if size == target.PtrSize {
+ switch size {
+ case target.PtrSize:
return target.any.ptrPtr
- } else if size == 8 {
+ case 8:
return target.any.ptr64
}
panic(fmt.Sprintf("bad pointer size %v", size))
diff --git a/prog/meta.go b/prog/meta.go
index 5c23627df..3524963c0 100644
--- a/prog/meta.go
+++ b/prog/meta.go
@@ -22,7 +22,7 @@ func GitRevisionKnown() bool {
}
func init() {
- GitRevisionBase = strings.Replace(GitRevision, "+", "", -1)
+ GitRevisionBase = strings.ReplaceAll(GitRevision, "+", "")
if gitRevisionDate != "" {
var err error
if GitRevisionDate, err = time.Parse("20060102-150405", gitRevisionDate); err != nil {
diff --git a/prog/minimization_test.go b/prog/minimization_test.go
index e8f1d40e5..696e9e446 100644
--- a/prog/minimization_test.go
+++ b/prog/minimization_test.go
@@ -272,7 +272,8 @@ getuid()
11,
func(p *Prog, callIndex int) bool {
pp := strings.TrimSpace(string(p.Serialize()))
- if attempt == 0 {
+ switch attempt {
+ case 0:
if pp == strings.TrimSpace(`
getpid()
r0 = open(&(0x7f0000000040)='./file0', 0x0, 0x0)
@@ -289,7 +290,7 @@ fcntl$getflags(r0, 0x0)
`) {
return false
}
- } else if attempt == 1 {
+ case 1:
if pp == strings.TrimSpace(`
r0 = open(&(0x7f0000000040)='./file0', 0x0, 0x0)
read(r0, &(0x7f0000000040), 0x10)
@@ -301,7 +302,7 @@ close(r2)
`) {
return true
}
- } else {
+ default:
return false
}
panic(fmt.Sprintf("unexpected candidate on attempt %v:\n%v", attempt, pp))
diff --git a/sys/openbsd/init.go b/sys/openbsd/init.go
index 5d0c3a77c..80cb6d4f0 100644
--- a/sys/openbsd/init.go
+++ b/sys/openbsd/init.go
@@ -170,20 +170,21 @@ func (arch *arch) neutralizeRlimit(c *prog.Call) {
rlimitMin := uint64(0)
rlimitMax := uint64(math.MaxUint64)
resource := c.Args[0].(*prog.ConstArg).Val & rlimitMask
- if resource == arch.RLIMIT_DATA {
+ switch resource {
+ case arch.RLIMIT_DATA:
// OpenBSD performs a strict validation of the RLIMIT_DATA soft
// limit during memory allocation. Lowering the same limit could
// cause syz-executor to run out of memory quickly. Therefore
// make sure to not go lower than the default soft limit for the
// staff group.
rlimitMin = 1536 * 1024 * 1024
- } else if resource == arch.RLIMIT_STACK {
+ case arch.RLIMIT_STACK:
// Do not allow the stack to grow beyond the initial soft limit
// chosen by syz-executor. Otherwise, syz-executor will most
// likely not be able to perform any more heap allocations since
// they majority of memory is reserved for the stack.
rlimitMax = 1 * 1024 * 1024
- } else {
+ default:
return
}
diff --git a/sys/targets/targets.go b/sys/targets/targets.go
index 1166134bc..67ae9bba4 100644
--- a/sys/targets/targets.go
+++ b/sys/targets/targets.go
@@ -675,7 +675,7 @@ func init() {
// Fix cflags by replacing compiler's -m32 option with -m31
if arch == S390x {
for i := range target.CFlags {
- target.CFlags[i] = strings.Replace(target.CFlags[i], "-m32", "-m31", -1)
+ target.CFlags[i] = strings.ReplaceAll(target.CFlags[i], "-m32", "-m31")
}
}
if runtime.GOOS == OpenBSD {
@@ -924,7 +924,7 @@ func (target *Target) replaceSourceDir(param *string, sourceDir string) {
target.BrokenCompiler = "SOURCEDIR is not set"
return
}
- *param = strings.Replace(*param, sourceDirVar, sourceDir, -1)
+ *param = strings.ReplaceAll(*param, sourceDirVar, sourceDir)
}
func (target *Target) lazyInit() {
diff --git a/syz-ci/jobs.go b/syz-ci/jobs.go
index a9bb23abc..ee2e861b3 100644
--- a/syz-ci/jobs.go
+++ b/syz-ci/jobs.go
@@ -461,7 +461,7 @@ func (jp *JobProcessor) bisect(job *Job, mgrcfg *mgrconfig.Config) error {
cfg := &bisect.Config{
Trace: &debugtracer.GenericTracer{
TraceWriter: io.MultiWriter(trace, log.VerboseWriter(3)),
- OutDir: osutil.Abs(filepath.Join("jobs", "debug", strings.Replace(req.ID, "|", "_", -1))),
+ OutDir: osutil.Abs(filepath.Join("jobs", "debug", strings.ReplaceAll(req.ID, "|", "_"))),
},
// Out of 1049 cause bisections that we have now:
// - 891 finished under 6h (84.9%)
@@ -641,9 +641,9 @@ func (jp *JobProcessor) testPatch(job *Job, mgrcfg *mgrconfig.Config) error {
// Testing of patches for these bugs fail now because of the config, so we disable it as a work-around.
// Ideally we have a new pahole and then we can remove this hack. That's issue #2096.
// pkg/vcs/linux.go also disables it for the bisection process.
- req.KernelConfig = bytes.Replace(req.KernelConfig,
+ req.KernelConfig = bytes.ReplaceAll(req.KernelConfig,
[]byte("CONFIG_DEBUG_INFO_BTF=y"),
- []byte("# CONFIG_DEBUG_INFO_BTF is not set"), -1)
+ []byte("# CONFIG_DEBUG_INFO_BTF is not set"))
log.Logf(0, "job: building kernel...")
kernelConfig, details, err := env.BuildKernel(buildCfg)
diff --git a/syz-ci/jobs_test.go b/syz-ci/jobs_test.go
index 1ad7b7efc..547fd96e2 100644
--- a/syz-ci/jobs_test.go
+++ b/syz-ci/jobs_test.go
@@ -125,7 +125,7 @@ func TestAggregateTestResults(t *testing.T) {
if rep != nil {
gotOutput = rep.rawOutput
}
- if fmt.Sprint(test.rawOut) != fmt.Sprint(gotOutput) {
+ if fmt.Sprint(string(test.rawOut)) != fmt.Sprint(string(gotOutput)) {
t.Errorf("test #%v: got raw out: %q, want: %q", i, gotOutput, test.rawOut)
}
}
diff --git a/syz-ci/manager.go b/syz-ci/manager.go
index f21933118..ab1e0820b 100644
--- a/syz-ci/manager.go
+++ b/syz-ci/manager.go
@@ -1074,7 +1074,7 @@ func uploadFileHTTPPut(ctx context.Context, URL string, file io.Reader) error {
return fmt.Errorf("failed to perform HTTP PUT request: %w", err)
}
defer resp.Body.Close()
- if !(resp.StatusCode >= 200 && resp.StatusCode <= 299) {
+ if resp.StatusCode < 200 || resp.StatusCode > 299 {
return fmt.Errorf("HTTP PUT failed with status code: %v", resp.StatusCode)
}
return nil
diff --git a/syz-ci/syz-ci.go b/syz-ci/syz-ci.go
index 3cefab1bc..7df27b683 100644
--- a/syz-ci/syz-ci.go
+++ b/syz-ci/syz-ci.go
@@ -317,10 +317,10 @@ func main() {
http.HandleFunc("/upload_cover", func(w http.ResponseWriter, r *http.Request) {
for _, mgr := range managers {
if err := mgr.uploadCoverReport(ctx); err != nil {
- w.Write([]byte(fmt.Sprintf("failed for %v: %v <br>\n", mgr.name, err)))
+ fmt.Fprintf(w, "failed for %v: %v <br>\n", mgr.name, err)
return
}
- w.Write([]byte(fmt.Sprintf("upload cover for %v <br>\n", mgr.name)))
+ fmt.Fprintf(w, "upload cover for %v <br>\n", mgr.name)
}
})
diff --git a/syz-cluster/pkg/emailclient/sender.go b/syz-cluster/pkg/emailclient/sender.go
index 879de218a..5bfd86823 100644
--- a/syz-cluster/pkg/emailclient/sender.go
+++ b/syz-cluster/pkg/emailclient/sender.go
@@ -29,13 +29,14 @@ func (item *Email) recipients() []string {
type Sender func(context.Context, *Email) (string, error)
func MakeSender(ctx context.Context, cfg *app.EmailConfig) (Sender, error) {
- if cfg.Sender == app.SenderSMTP {
+ switch cfg.Sender {
+ case app.SenderSMTP:
sender, err := newSMTPSender(ctx, cfg)
if err != nil {
return nil, err
}
return sender.Send, nil
- } else if cfg.Sender == app.SenderDashapi {
+ case app.SenderDashapi:
return makeDashapiSender(cfg)
}
return nil, fmt.Errorf("unsupported sender type: %q", cfg.Sender)
diff --git a/syz-hub/http.go b/syz-hub/http.go
index 06f777f34..14fa43f7f 100644
--- a/syz-hub/http.go
+++ b/syz-hub/http.go
@@ -70,7 +70,7 @@ func (hub *Hub) httpSummary(w http.ResponseWriter, r *http.Request) {
}
func compileTemplate(html string) *template.Template {
- return template.Must(template.New("").Parse(strings.Replace(html, "{{STYLE}}", htmlStyle, -1)))
+ return template.Must(template.New("").Parse(strings.ReplaceAll(html, "{{STYLE}}", htmlStyle)))
}
type UISummaryData struct {
diff --git a/syz-manager/manager.go b/syz-manager/manager.go
index 9e704c0fb..fedf6a9e8 100644
--- a/syz-manager/manager.go
+++ b/syz-manager/manager.go
@@ -1123,7 +1123,8 @@ func (mgr *Manager) MachineChecked(features flatrpc.Feature,
mgr.setPhaseLocked(phaseLoadedCorpus)
opts := fuzzer.DefaultExecOpts(mgr.cfg, features, *flagDebug)
- if mgr.mode == ModeFuzzing || mgr.mode == ModeCorpusTriage {
+ switch mgr.mode {
+ case ModeFuzzing, ModeCorpusTriage:
corpusUpdates := make(chan corpus.NewItemEvent, 128)
mgr.corpus = corpus.NewFocusedCorpus(context.Background(),
corpusUpdates, mgr.coverFilters.Areas)
@@ -1177,13 +1178,13 @@ func (mgr *Manager) MachineChecked(features flatrpc.Feature,
}), nil
}
return source, nil
- } else if mgr.mode == ModeCorpusRun {
+ case ModeCorpusRun:
ctx := &corpusRunner{
candidates: candidates,
rnd: rand.New(rand.NewSource(time.Now().UnixNano())),
}
return queue.DefaultOpts(ctx, opts), nil
- } else if mgr.mode == ModeRunTests {
+ case ModeRunTests:
ctx := &runtest.Context{
Dir: filepath.Join(mgr.cfg.Syzkaller, "sys", mgr.cfg.Target.OS, "test"),
Target: mgr.cfg.Target,
@@ -1205,7 +1206,7 @@ func (mgr *Manager) MachineChecked(features flatrpc.Feature,
mgr.exit("tests")
}()
return ctx, nil
- } else if mgr.mode == ModeIfaceProbe {
+ case ModeIfaceProbe:
exec := queue.Plain()
go func() {
res, err := ifaceprobe.Run(vm.ShutdownCtx(), mgr.cfg, features, exec)
@@ -1283,7 +1284,8 @@ func (mgr *Manager) fuzzerLoop(fuzzer *fuzzer.Fuzzer) {
mgr.exit("corpus triage")
}
mgr.mu.Lock()
- if mgr.phase == phaseLoadedCorpus {
+ switch mgr.phase {
+ case phaseLoadedCorpus:
if !mgr.cfg.Snapshot {
mgr.serv.TriagedCorpus()
}
@@ -1294,7 +1296,7 @@ func (mgr *Manager) fuzzerLoop(fuzzer *fuzzer.Fuzzer) {
} else {
mgr.setPhaseLocked(phaseTriagedHub)
}
- } else if mgr.phase == phaseQueriedHub {
+ case phaseQueriedHub:
mgr.setPhaseLocked(phaseTriagedHub)
}
mgr.mu.Unlock()
diff --git a/tools/syz-check/check.go b/tools/syz-check/check.go
index f153db6d1..8021e8720 100644
--- a/tools/syz-check/check.go
+++ b/tools/syz-check/check.go
@@ -620,7 +620,7 @@ func checkNetlinkAttr(typ *prog.StructType, policy nlaPolicy) string {
// This is a common case that occurs several times: limit on min value of 1.
// Not worth fixing (at least not in initial batch), it just crosses out a
// single value of 0, which we shuold test anyway.
- if !(policy.validation == NLA_VALIDATE_MIN && policy.minVal == 1) {
+ if policy.validation != NLA_VALIDATE_MIN || policy.minVal != 1 {
return fmt.Sprintf("bad min value %v, expect %v",
int64(valMin), policy.minVal)
}
diff --git a/vm/proxyapp/proxyappclient.go b/vm/proxyapp/proxyappclient.go
index 32a0b0b96..cbd731550 100644
--- a/vm/proxyapp/proxyappclient.go
+++ b/vm/proxyapp/proxyappclient.go
@@ -335,7 +335,7 @@ func (proxy *ProxyApp) doLogPooling(writer io.Writer) {
return
}
if log.V(reply.Verbosity) {
- writer.Write([]byte(fmt.Sprintf("ProxyAppLog: %v", reply.Log)))
+ fmt.Fprintf(writer, "ProxyAppLog: %v", reply.Log)
}
}
}
@@ -591,7 +591,7 @@ type stdInOutCloser struct {
func clientErrorf(writer io.Writer) func(fmt string, s ...interface{}) {
return func(f string, s ...interface{}) {
- writer.Write([]byte(fmt.Sprintf(f, s...)))
+ fmt.Fprintf(writer, f, s)
writer.Write([]byte("\nSYZFAIL: proxy app plugin error\n"))
}
}
diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go
index ba1ecf979..3bf546aa2 100644
--- a/vm/qemu/qemu.go
+++ b/vm/qemu/qemu.go
@@ -335,7 +335,7 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) {
return nil, err
}
initFile := filepath.Join(workdir, "init.sh")
- if err := osutil.WriteExecFile(initFile, []byte(strings.Replace(initScript, "{{KEY}}", sshkey, -1))); err != nil {
+ if err := osutil.WriteExecFile(initFile, []byte(strings.ReplaceAll(initScript, "{{KEY}}", sshkey))); err != nil {
return nil, fmt.Errorf("failed to create init file: %w", err)
}
}