From 4359978ef22a22ddd5a19adf18cbc80cb44244fb Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Thu, 23 Feb 2023 14:28:18 +0100 Subject: all: ioutil is deprecated in go1.19 (#3718) --- pkg/asset/storage_test.go | 5 ++--- pkg/ast/parser.go | 4 ++-- pkg/ast/parser_test.go | 6 +++--- pkg/ast/test_util.go | 4 ++-- pkg/auth/auth.go | 4 ++-- pkg/auth/jwt.go | 3 +-- pkg/build/cuttlefish.go | 4 ++-- pkg/build/linux.go | 5 ++--- pkg/build/linux_linux.go | 3 +-- pkg/compiler/compiler_test.go | 4 ++-- pkg/compiler/const_file.go | 4 ++-- pkg/compiler/const_file_test.go | 5 ++--- pkg/compiler/consts_test.go | 4 ++-- pkg/config/config.go | 4 ++-- pkg/cover/backend/dwarf.go | 4 ++-- pkg/cover/html.go | 4 ++-- pkg/csource/build.go | 3 +-- pkg/db/db.go | 3 +-- pkg/db/db_test.go | 7 +++---- pkg/email/parser.go | 5 ++--- pkg/gce/gce.go | 4 ++-- pkg/host/machine_info_linux.go | 9 ++++----- pkg/host/syscalls_linux.go | 7 +++---- pkg/image/compression.go | 3 +-- pkg/image/compression_test.go | 4 ++-- pkg/ipc/ipc.go | 3 +-- pkg/kconfig/config.go | 4 ++-- pkg/kconfig/kconfig.go | 6 +++--- pkg/mgrconfig/load.go | 3 +-- pkg/osutil/fileutil.go | 3 +-- pkg/osutil/osutil.go | 9 ++++----- pkg/osutil/osutil_linux.go | 3 +-- pkg/osutil/osutil_unix.go | 3 +-- pkg/report/linux_test.go | 10 +++++----- pkg/report/report_test.go | 10 +++++----- pkg/runtest/run.go | 7 +++---- pkg/tool/flags_test.go | 4 ++-- 37 files changed, 79 insertions(+), 98 deletions(-) (limited to 'pkg') diff --git a/pkg/asset/storage_test.go b/pkg/asset/storage_test.go index 9652c9d2a..fb45f5fad 100644 --- a/pkg/asset/storage_test.go +++ b/pkg/asset/storage_test.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "reflect" "strings" "testing" @@ -80,7 +79,7 @@ func validateGzip(res *uploadedFile, expected []byte) error { return fmt.Errorf("gzip.NewReader failed: %w", err) } defer reader.Close() - body, err := ioutil.ReadAll(reader) + body, err := io.ReadAll(reader) if err != nil { return fmt.Errorf("read of ungzipped content failed: %w", err) } @@ -102,7 +101,7 @@ func validateXz(res *uploadedFile, expected []byte) error { if err != nil { return fmt.Errorf("xz reader failed: %w", err) } - out, err := ioutil.ReadAll(xzReader) + out, err := io.ReadAll(xzReader) if err != nil { return fmt.Errorf("xz decompression failed: %w", err) } diff --git a/pkg/ast/parser.go b/pkg/ast/parser.go index b2709e2ed..bb08a0b7e 100644 --- a/pkg/ast/parser.go +++ b/pkg/ast/parser.go @@ -6,7 +6,7 @@ package ast import ( "errors" "fmt" - "io/ioutil" + "os" "path/filepath" "strconv" "strings" @@ -62,7 +62,7 @@ func ParseGlob(glob string, errorHandler ErrorHandler) *Description { } desc := &Description{} for _, f := range files { - data, err := ioutil.ReadFile(f) + data, err := os.ReadFile(f) if err != nil { errorHandler(Pos{}, fmt.Sprintf("failed to read input file: %v", err)) return nil diff --git a/pkg/ast/parser_test.go b/pkg/ast/parser_test.go index d3a9049bc..cecdcc9b2 100644 --- a/pkg/ast/parser_test.go +++ b/pkg/ast/parser_test.go @@ -5,7 +5,7 @@ package ast import ( "bytes" - "io/ioutil" + "os" "path/filepath" "reflect" "strings" @@ -21,7 +21,7 @@ func TestParseAll(t *testing.T) { } files = append(files, filepath.FromSlash("testdata/all.txt")) for _, file := range files { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err != nil { t.Fatalf("failed to read file: %v", err) } @@ -124,7 +124,7 @@ var parseTests = []struct { } func TestErrors(t *testing.T) { - files, err := ioutil.ReadDir("testdata") + files, err := os.ReadDir("testdata") if err != nil { t.Fatal(err) } diff --git a/pkg/ast/test_util.go b/pkg/ast/test_util.go index 697b34505..921232c96 100644 --- a/pkg/ast/test_util.go +++ b/pkg/ast/test_util.go @@ -7,7 +7,7 @@ import ( "bufio" "bytes" "fmt" - "io/ioutil" + "os" "path/filepath" "regexp" "sort" @@ -29,7 +29,7 @@ type errorDesc struct { } func NewErrorMatcher(t *testing.T, file string) *ErrorMatcher { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err != nil { t.Fatalf("failed to open input file: %v", err) } diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index af8432a34..a9a66809a 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -29,7 +29,7 @@ package auth import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strconv" @@ -81,7 +81,7 @@ func (auth *Endpoint) queryTokenInfo(tokenValue string) (*jwtClaims, error) { if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("verification failed %v", resp.StatusCode) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/pkg/auth/jwt.go b/pkg/auth/jwt.go index f6d219323..c1f034a2c 100644 --- a/pkg/auth/jwt.go +++ b/pkg/auth/jwt.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "strings" "sync" @@ -65,7 +64,7 @@ func retrieveJwtToken(ctor requestCtor, doer requestDoer) (*expiringToken, error return nil, err } defer resp.Body.Close() - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/pkg/build/cuttlefish.go b/pkg/build/cuttlefish.go index 42ec8af26..3777467a8 100644 --- a/pkg/build/cuttlefish.go +++ b/pkg/build/cuttlefish.go @@ -7,7 +7,7 @@ import ( "archive/tar" "compress/gzip" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "strings" @@ -58,7 +58,7 @@ func (c cuttlefish) readCompiler(archivePath string) (string, error) { h, err := tr.Next() for ; err == nil; h, err = tr.Next() { if filepath.Base(h.Name) == "compile.h" { - bytes, err := ioutil.ReadAll(tr) + bytes, err := io.ReadAll(tr) if err != nil { return "", err } diff --git a/pkg/build/linux.go b/pkg/build/linux.go index bb6e66ef3..112e2dfab 100644 --- a/pkg/build/linux.go +++ b/pkg/build/linux.go @@ -10,7 +10,6 @@ import ( "debug/elf" "encoding/hex" "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -114,7 +113,7 @@ func (linux linux) buildKernel(params Params) error { } func (linux) createImage(params Params, kernelPath string) error { - tempDir, err := ioutil.TempDir("", "syz-build") + tempDir, err := os.MkdirTemp("", "syz-build") if err != nil { return err } @@ -239,7 +238,7 @@ func LinuxKernelImage(arch string) string { var linuxCompilerRegexp = regexp.MustCompile(`#define\s+LINUX_COMPILER\s+"(.*)"`) func queryLinuxCompiler(kernelDir string) (string, error) { - bytes, err := ioutil.ReadFile(filepath.Join(kernelDir, "include", "generated", "compile.h")) + bytes, err := os.ReadFile(filepath.Join(kernelDir, "include", "generated", "compile.h")) if err != nil { return "", err } diff --git a/pkg/build/linux_linux.go b/pkg/build/linux_linux.go index 55f21a7ee..d22fea678 100644 --- a/pkg/build/linux_linux.go +++ b/pkg/build/linux_linux.go @@ -5,7 +5,6 @@ package build import ( "fmt" - "io/ioutil" "os" "path/filepath" "syscall" @@ -37,7 +36,7 @@ func embedFiles(params Params, callback func(mountDir string) error) error { if params.CmdlineFile != "" { return fmt.Errorf("cmdline file is not supported for linux images") } - tempDir, err := ioutil.TempDir("", "syz-build") + tempDir, err := os.MkdirTemp("", "syz-build") if err != nil { return err } diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index 79735d10a..be40e817b 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -7,7 +7,7 @@ import ( "bytes" "flag" "fmt" - "io/ioutil" + "os" "path/filepath" "reflect" "sort" @@ -112,7 +112,7 @@ func TestData(t *testing.T) { } if formatted := ast.Format(astDesc); !bytes.Equal(em.Data, formatted) { if *flagUpdate { - ioutil.WriteFile(fileName, formatted, 0644) + os.WriteFile(fileName, formatted, 0644) } t.Fatalf("description is not formatted") } diff --git a/pkg/compiler/const_file.go b/pkg/compiler/const_file.go index 78f3b03f9..0df0bb0ca 100644 --- a/pkg/compiler/const_file.go +++ b/pkg/compiler/const_file.go @@ -7,7 +7,7 @@ import ( "bufio" "bytes" "fmt" - "io/ioutil" + "os" "path/filepath" "regexp" "sort" @@ -168,7 +168,7 @@ func DeserializeConstFile(glob string, eh ast.ErrorHandler) *ConstFile { cf := NewConstFile() oldFormat := regexp.MustCompile(`_([a-z0-9]+)\.const$`) for _, f := range files { - data, err := ioutil.ReadFile(f) + data, err := os.ReadFile(f) if err != nil { eh(ast.Pos{}, fmt.Sprintf("failed to read const file: %v", err)) return nil diff --git a/pkg/compiler/const_file_test.go b/pkg/compiler/const_file_test.go index b38d0795d..ccfce4c95 100644 --- a/pkg/compiler/const_file_test.go +++ b/pkg/compiler/const_file_test.go @@ -4,7 +4,6 @@ package compiler import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -91,7 +90,7 @@ CONST5_SOME_UNDEFINED2 = 100, arch3:??? t.Fatal(diff) } { - file, err := ioutil.TempFile("", "syz-const") + file, err := os.CreateTemp("", "syz-const") if err != nil { t.Fatal(err) } @@ -112,7 +111,7 @@ CONST5_SOME_UNDEFINED2 = 100, arch3:??? dir := t.TempDir() for name, arch := range arches { file := filepath.Join(dir, "consts_"+name+".const") - if err := ioutil.WriteFile(file, []byte(arch.oldFormat), 0600); err != nil { + if err := os.WriteFile(file, []byte(arch.oldFormat), 0600); err != nil { t.Fatal(err) } } diff --git a/pkg/compiler/consts_test.go b/pkg/compiler/consts_test.go index 685525bc9..a0e4c1c8d 100644 --- a/pkg/compiler/consts_test.go +++ b/pkg/compiler/consts_test.go @@ -4,7 +4,7 @@ package compiler import ( - "io/ioutil" + "os" "path/filepath" "reflect" "sort" @@ -15,7 +15,7 @@ import ( ) func TestExtractConsts(t *testing.T) { - data, err := ioutil.ReadFile(filepath.Join("testdata", "consts.txt")) + data, err := os.ReadFile(filepath.Join("testdata", "consts.txt")) if err != nil { t.Fatalf("failed to read input file: %v", err) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 8eb43fa58..503a5b466 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -7,7 +7,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "os" "regexp" "github.com/google/syzkaller/pkg/osutil" @@ -17,7 +17,7 @@ func LoadFile(filename string, cfg interface{}) error { if filename == "" { return fmt.Errorf("no config file specified") } - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { return fmt.Errorf("failed to read config file: %v", err) } diff --git a/pkg/cover/backend/dwarf.go b/pkg/cover/backend/dwarf.go index e696421de..6aa1e5827 100644 --- a/pkg/cover/backend/dwarf.go +++ b/pkg/cover/backend/dwarf.go @@ -10,7 +10,7 @@ import ( "debug/elf" "encoding/binary" "fmt" - "io/ioutil" + "io" "path/filepath" "runtime" "sort" @@ -503,7 +503,7 @@ func objdump(target *targets.Target, mod *Module) ([2][]uint64, error) { pcs[0] = append(pcs[0], pc+mod.Addr) } } - stderrOut, _ := ioutil.ReadAll(stderr) + stderrOut, _ := io.ReadAll(stderr) if err := cmd.Wait(); err != nil { return pcs, fmt.Errorf("failed to run objdump on %v: %v\n%s", mod.Path, err, stderrOut) } diff --git a/pkg/cover/html.go b/pkg/cover/html.go index 4a0e4e971..c5c18c698 100644 --- a/pkg/cover/html.go +++ b/pkg/cover/html.go @@ -11,9 +11,9 @@ import ( "html" "html/template" "io" - "io/ioutil" "math" "net/http" + "os" "path/filepath" "sort" "strconv" @@ -721,7 +721,7 @@ func percent(covered, total int) int { } func parseFile(fn string) ([][]byte, error) { - data, err := ioutil.ReadFile(fn) + data, err := os.ReadFile(fn) if err != nil { return nil, err } diff --git a/pkg/csource/build.go b/pkg/csource/build.go index 0855dc038..af41f66d3 100644 --- a/pkg/csource/build.go +++ b/pkg/csource/build.go @@ -6,7 +6,6 @@ package csource import ( "bytes" "fmt" - "io/ioutil" "os" "runtime" @@ -68,7 +67,7 @@ func build(target *prog.Target, src []byte, file string, cflags ...string) (stri if err != nil { os.Remove(bin) if file != "" { - src, _ = ioutil.ReadFile(file) + src, _ = os.ReadFile(file) } return "", fmt.Errorf("failed to build program:\n%s\n%s\ncompiler invocation: %v %v", src, out, compiler, flags) diff --git a/pkg/db/db.go b/pkg/db/db.go index ae0c374e9..203761dfa 100644 --- a/pkg/db/db.go +++ b/pkg/db/db.go @@ -15,7 +15,6 @@ import ( "encoding/binary" "fmt" "io" - "io/ioutil" "os" "github.com/google/syzkaller/pkg/hash" @@ -265,7 +264,7 @@ func deserializeRecord(r *bufio.Reader) (key string, val []byte, seq uint64, err } if valLen != 0 { fr := flate.NewReader(&io.LimitedReader{R: r, N: int64(valLen)}) - if val, err = ioutil.ReadAll(fr); err != nil { + if val, err = io.ReadAll(fr); err != nil { return } fr.Close() diff --git a/pkg/db/db_test.go b/pkg/db/db_test.go index f6917ef17..8319e73d1 100644 --- a/pkg/db/db_test.go +++ b/pkg/db/db_test.go @@ -5,7 +5,6 @@ package db import ( "fmt" - "io/ioutil" "math/rand" "os" "reflect" @@ -120,7 +119,7 @@ func TestLarge(t *testing.T) { } func TestOpenInvalid(t *testing.T) { - f, err := ioutil.TempFile("", "syz-db-test") + f, err := os.CreateTemp("", "syz-db-test") if err != nil { t.Error(err) } @@ -141,7 +140,7 @@ func TestOpenInaccessible(t *testing.T) { if os.Getuid() == 0 { t.Skip("opening inaccessible file won't fail under root") } - f, err := ioutil.TempFile("", "syz-db-test") + f, err := os.CreateTemp("", "syz-db-test") if err != nil { t.Error(err) } @@ -171,7 +170,7 @@ func TestOpenCorrupted(t *testing.T) { if err := db.Flush(); err != nil { t.Fatalf("failed to flush db: %v", err) } - data, err := ioutil.ReadFile(fn) + data, err := os.ReadFile(fn) if err != nil { t.Fatalf("failed to read db: %v", err) } diff --git a/pkg/email/parser.go b/pkg/email/parser.go index e2d3d0ab8..9de71f731 100644 --- a/pkg/email/parser.go +++ b/pkg/email/parser.go @@ -7,7 +7,6 @@ import ( "encoding/base64" "fmt" "io" - "io/ioutil" "mime" "mime/multipart" "mime/quotedprintable" @@ -367,14 +366,14 @@ func parseBody(r io.Reader, headers mail.Header) ([]byte, [][]byte, error) { } disp, _, _ := mime.ParseMediaType(headers.Get("Content-Disposition")) if disp == "attachment" { - attachment, err := ioutil.ReadAll(r) + attachment, err := io.ReadAll(r) if err != nil { return nil, nil, fmt.Errorf("failed to read email body: %v", err) } return nil, [][]byte{attachment}, nil } if mediaType == "text/plain" { - body, err := ioutil.ReadAll(r) + body, err := io.ReadAll(r) if err != nil { return nil, nil, fmt.Errorf("failed to read email body: %v", err) } diff --git a/pkg/gce/gce.go b/pkg/gce/gce.go index 7a72f1bfd..f461df604 100644 --- a/pkg/gce/gce.go +++ b/pkg/gce/gce.go @@ -13,7 +13,7 @@ package gce import ( "fmt" - "io/ioutil" + "io" "math/rand" "net/http" "strings" @@ -342,7 +342,7 @@ func (ctx *Context) getMeta(path string) (string, error) { return "", err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return "", err } diff --git a/pkg/host/machine_info_linux.go b/pkg/host/machine_info_linux.go index fb05382ba..fc3664c42 100644 --- a/pkg/host/machine_info_linux.go +++ b/pkg/host/machine_info_linux.go @@ -7,7 +7,6 @@ import ( "bufio" "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -86,7 +85,7 @@ func allEqual(slice []string) bool { } func readKVMInfo(buffer *bytes.Buffer) error { - files, err := ioutil.ReadDir("/sys/module/") + files, err := os.ReadDir("/sys/module/") if err != nil { return err } @@ -98,7 +97,7 @@ func readKVMInfo(buffer *bytes.Buffer) error { } paramPath := filepath.Join("/sys", "module", name, "parameters") - params, err := ioutil.ReadDir(paramPath) + params, err := os.ReadDir(paramPath) if err != nil { if os.IsNotExist(err) { continue @@ -113,7 +112,7 @@ func readKVMInfo(buffer *bytes.Buffer) error { fmt.Fprintf(buffer, "/sys/module/%s:\n", name) for _, key := range params { keyName := key.Name() - data, err := ioutil.ReadFile(filepath.Join(paramPath, keyName)) + data, err := os.ReadFile(filepath.Join(paramPath, keyName)) if err != nil { return err } @@ -127,7 +126,7 @@ func readKVMInfo(buffer *bytes.Buffer) error { func getModulesInfo() ([]KernelModule, error) { var modules []KernelModule - modulesText, _ := ioutil.ReadFile("/proc/modules") + modulesText, _ := os.ReadFile("/proc/modules") re := regexp.MustCompile(`(\w+) .*(0[x|X][a-fA-F0-9]+)[^\n]*`) for _, m := range re.FindAllSubmatch(modulesText, -1) { addr, err := strconv.ParseUint(string(m[2]), 0, 64) diff --git a/pkg/host/syscalls_linux.go b/pkg/host/syscalls_linux.go index 6425fcce7..67efd9295 100644 --- a/pkg/host/syscalls_linux.go +++ b/pkg/host/syscalls_linux.go @@ -6,7 +6,6 @@ package host import ( "bytes" "fmt" - "io/ioutil" "os" "regexp" "runtime" @@ -58,7 +57,7 @@ func isSupportedSyscall(c *prog.Syscall, target *prog.Target) (bool, string) { // Kallsyms seems to be the most reliable and fast. That's what we use first. // If kallsyms is not present, we fallback to execution of syscalls. kallsymsOnce.Do(func() { - kallsyms, _ := ioutil.ReadFile("/proc/kallsyms") + kallsyms, _ := os.ReadFile("/proc/kallsyms") if len(kallsyms) == 0 { return } @@ -390,7 +389,7 @@ func isSupportedSyzOpenDev(sandbox string, c *prog.Syscall) (bool, string) { func isSupportedLSM(c *prog.Syscall) string { lsmOnce.Do(func() { - data, err := ioutil.ReadFile("/sys/kernel/security/lsm") + data, err := os.ReadFile("/sys/kernel/security/lsm") if err != nil { // securityfs may not be mounted, but it does not mean // that no LSMs are enabled. @@ -522,7 +521,7 @@ func isSupportedMount(c *prog.Syscall, sandbox string) (bool, string) { func isSupportedFilesystem(fstype string) (bool, string) { filesystemsOnce.Do(func() { - filesystems, _ = ioutil.ReadFile("/proc/filesystems") + filesystems, _ = os.ReadFile("/proc/filesystems") }) if !bytes.Contains(filesystems, []byte("\t"+fstype+"\n")) { return false, fmt.Sprintf("/proc/filesystems does not contain %v", fstype) diff --git a/pkg/image/compression.go b/pkg/image/compression.go index c374ed07b..70e314ae5 100644 --- a/pkg/image/compression.go +++ b/pkg/image/compression.go @@ -9,7 +9,6 @@ import ( "encoding/base64" "fmt" "io" - "io/ioutil" ) func Compress(rawData []byte) []byte { @@ -37,7 +36,7 @@ func MustDecompress(compressed []byte) (data []byte, dtor func()) { } func DecompressCheck(compressed []byte) error { - return decompressWriter(ioutil.Discard, compressed) + return decompressWriter(io.Discard, compressed) } func decompressWriter(w io.Writer, compressed []byte) error { diff --git a/pkg/image/compression_test.go b/pkg/image/compression_test.go index 15a225052..08caa40d6 100644 --- a/pkg/image/compression_test.go +++ b/pkg/image/compression_test.go @@ -6,8 +6,8 @@ package image_test import ( "bytes" "fmt" - "io/ioutil" "math/rand" + "os" "path/filepath" "testing" @@ -51,7 +51,7 @@ func TestEncode(t *testing.T) { func BenchmarkDecompress(b *testing.B) { // Extract the largest image seed. - data, err := ioutil.ReadFile(filepath.FromSlash("../../sys/linux/test/syz_mount_image_gfs2_0")) + data, err := os.ReadFile(filepath.FromSlash("../../sys/linux/test/syz_mount_image_gfs2_0")) if err != nil { b.Fatal(err) } diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go index 33e87f706..5485fd5dd 100644 --- a/pkg/ipc/ipc.go +++ b/pkg/ipc/ipc.go @@ -6,7 +6,6 @@ package ipc import ( "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -551,7 +550,7 @@ type callReply struct { func makeCommand(pid int, bin []string, config *Config, inFile, outFile *os.File, outmem []byte, tmpDirPath string) (*command, error) { - dir, err := ioutil.TempDir(tmpDirPath, "syzkaller-testdir") + dir, err := os.MkdirTemp(tmpDirPath, "syzkaller-testdir") if err != nil { return nil, fmt.Errorf("failed to create temp dir: %v", err) } diff --git a/pkg/kconfig/config.go b/pkg/kconfig/config.go index 70bdb1b17..a9c571b1d 100644 --- a/pkg/kconfig/config.go +++ b/pkg/kconfig/config.go @@ -7,7 +7,7 @@ import ( "bufio" "bytes" "fmt" - "io/ioutil" + "os" "regexp" ) @@ -105,7 +105,7 @@ func (cf *ConfigFile) Serialize() []byte { } func ParseConfig(file string) (*ConfigFile, error) { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err != nil { return nil, fmt.Errorf("failed to open .config file %v: %v", file, err) } diff --git a/pkg/kconfig/kconfig.go b/pkg/kconfig/kconfig.go index 84ea00afd..cd05cdbb1 100644 --- a/pkg/kconfig/kconfig.go +++ b/pkg/kconfig/kconfig.go @@ -8,7 +8,7 @@ package kconfig import ( "fmt" - "io/ioutil" + "os" "path/filepath" "strings" "sync" @@ -118,7 +118,7 @@ type kconfigParser struct { } func Parse(target *targets.Target, file string) (*KConfig, error) { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err != nil { return nil, fmt.Errorf("failed to open Kconfig file %v: %v", file, err) } @@ -329,7 +329,7 @@ func (kp *kconfigParser) includeSource(file string) { kp.newCurrent(nil) file = kp.expandString(file) file = filepath.Join(kp.baseDir, file) - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err != nil { kp.failf("%v", err) return diff --git a/pkg/mgrconfig/load.go b/pkg/mgrconfig/load.go index bef05faa4..30cb89417 100644 --- a/pkg/mgrconfig/load.go +++ b/pkg/mgrconfig/load.go @@ -5,7 +5,6 @@ package mgrconfig import ( "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -123,7 +122,7 @@ func Complete(cfg *Config) error { cfg.Workdir = osutil.Abs(cfg.Workdir) if cfg.WorkdirTemplate != "" { cfg.WorkdirTemplate = osutil.Abs(cfg.WorkdirTemplate) - if _, err := ioutil.ReadDir(cfg.WorkdirTemplate); err != nil { + if _, err := os.ReadDir(cfg.WorkdirTemplate); err != nil { return fmt.Errorf("failed to read workdir_template: %v", err) } } diff --git a/pkg/osutil/fileutil.go b/pkg/osutil/fileutil.go index f3bcf0e30..966560649 100644 --- a/pkg/osutil/fileutil.go +++ b/pkg/osutil/fileutil.go @@ -6,7 +6,6 @@ package osutil import ( "fmt" "io" - "io/ioutil" "os" ) @@ -54,7 +53,7 @@ func Rename(oldFile, newFile string) error { // WriteTempFile writes data to a temp file and returns its name. func WriteTempFile(data []byte) (string, error) { // Note: pkg/report knows about "syzkaller" prefix as it appears in crashes as process name. - f, err := ioutil.TempFile("", "syzkaller") + f, err := os.CreateTemp("", "syzkaller") if err != nil { return "", fmt.Errorf("failed to create a temp file: %v", err) } diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index 6ac96b344..ba1fb8729 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -9,7 +9,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -235,7 +234,7 @@ func CopyDirRecursively(srcDir, dstDir string) error { if err := MkdirAll(dstDir); err != nil { return err } - files, err := ioutil.ReadDir(srcDir) + files, err := os.ReadDir(srcDir) if err != nil { return err } @@ -273,7 +272,7 @@ func MkdirAll(dir string) error { } func WriteFile(filename string, data []byte) error { - return ioutil.WriteFile(filename, data, DefaultFilePerm) + return os.WriteFile(filename, data, DefaultFilePerm) } func WriteGzipStream(filename string, reader io.Reader) error { @@ -290,13 +289,13 @@ func WriteGzipStream(filename string, reader io.Reader) error { func WriteExecFile(filename string, data []byte) error { os.Remove(filename) - return ioutil.WriteFile(filename, data, DefaultExecPerm) + return os.WriteFile(filename, data, DefaultExecPerm) } // TempFile creates a unique temp filename. // Note: the file already exists when the function returns. func TempFile(prefix string) (string, error) { - f, err := ioutil.TempFile("", prefix) + f, err := os.CreateTemp("", prefix) if err != nil { return "", fmt.Errorf("failed to create temp file: %v", err) } diff --git a/pkg/osutil/osutil_linux.go b/pkg/osutil/osutil_linux.go index fb7a0670c..6585713ac 100644 --- a/pkg/osutil/osutil_linux.go +++ b/pkg/osutil/osutil_linux.go @@ -5,7 +5,6 @@ package osutil import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -20,7 +19,7 @@ import ( // RemoveAll is similar to os.RemoveAll, but can handle more cases. func RemoveAll(dir string) error { - files, _ := ioutil.ReadDir(dir) + files, _ := os.ReadDir(dir) for _, f := range files { name := filepath.Join(dir, f.Name()) if f.IsDir() { diff --git a/pkg/osutil/osutil_unix.go b/pkg/osutil/osutil_unix.go index 33cb09e40..5563fb5fd 100644 --- a/pkg/osutil/osutil_unix.go +++ b/pkg/osutil/osutil_unix.go @@ -9,7 +9,6 @@ package osutil import ( "fmt" "io" - "io/ioutil" "os" "os/signal" "path/filepath" @@ -54,7 +53,7 @@ func ProcessTempDir(where string) (string, error) { } func cleanupTempDir(path, pidfile string) bool { - data, err := ioutil.ReadFile(pidfile) + data, err := os.ReadFile(pidfile) if err == nil && len(data) > 0 { pid, err := strconv.Atoi(string(data)) if err == nil && pid > 1 { diff --git a/pkg/report/linux_test.go b/pkg/report/linux_test.go index 5aba2f19e..5f27b9e7d 100644 --- a/pkg/report/linux_test.go +++ b/pkg/report/linux_test.go @@ -6,7 +6,7 @@ package report import ( "bytes" "fmt" - "io/ioutil" + "os" "path/filepath" "reflect" "runtime" @@ -385,7 +385,7 @@ func TestDisassemblyInReports(t *testing.T) { } archPath := filepath.Join("testdata", "linux", "decompile") - subFolders, err := ioutil.ReadDir(archPath) + subFolders, err := os.ReadDir(archPath) if err != nil { t.Fatalf("disassembly reports failed: %v", err) } @@ -400,7 +400,7 @@ func TestDisassemblyInReports(t *testing.T) { } testPath := filepath.Join(archPath, obj.Name()) - testFiles, err := ioutil.ReadDir(testPath) + testFiles, err := os.ReadDir(testPath) if err != nil { t.Fatalf("failed to list tests for %v: %v", obj.Name(), err) } @@ -420,7 +420,7 @@ func TestDisassemblyInReports(t *testing.T) { func testDisassembly(t *testing.T, reporter *Reporter, linuxReporter *linux, testFilePrefix string) { t.Parallel() - input, err := ioutil.ReadFile(testFilePrefix + ".in") + input, err := os.ReadFile(testFilePrefix + ".in") if err != nil { t.Fatalf("failed to read input file: %v", err) } @@ -435,7 +435,7 @@ func testDisassembly(t *testing.T, reporter *Reporter, linuxReporter *linux, tes osutil.WriteFile(testFilePrefix+".out", result) } - output, err := ioutil.ReadFile(testFilePrefix + ".out") + output, err := os.ReadFile(testFilePrefix + ".out") if err != nil { t.Fatalf("failed to read output file: %v", err) } diff --git a/pkg/report/report_test.go b/pkg/report/report_test.go index cea8588b3..9503ce918 100644 --- a/pkg/report/report_test.go +++ b/pkg/report/report_test.go @@ -8,7 +8,7 @@ import ( "bytes" "flag" "fmt" - "io/ioutil" + "os" "path/filepath" "reflect" "regexp" @@ -44,7 +44,7 @@ type ParseTest struct { } func testParseFile(t *testing.T, reporter *Reporter, fn string) { - data, err := ioutil.ReadFile(fn) + data, err := os.ReadFile(fn) if err != nil { t.Fatal(err) } @@ -269,7 +269,7 @@ func updateReportTest(t *testing.T, test *ParseTest, title string, altTitles []s if test.HasReport { fmt.Fprintf(buf, "REPORT:\n%s", test.Report) } - if err := ioutil.WriteFile(test.FileName, buf.Bytes(), 0640); err != nil { + if err := os.WriteFile(test.FileName, buf.Bytes(), 0640); err != nil { t.Logf("failed to update test file: %v", err) } } @@ -317,7 +317,7 @@ func testRawGuiltyFile(t *testing.T, reporter *Reporter, fn string) { } func parseGuiltyTest(t *testing.T, fn string) (map[string]string, []byte) { - data, err := ioutil.ReadFile(fn) + data, err := os.ReadFile(fn) if err != nil { t.Fatal(err) } @@ -378,7 +378,7 @@ func readDir(t *testing.T, dir string) (files []string) { if !osutil.IsExist(dir) { return nil } - entries, err := ioutil.ReadDir(dir) + entries, err := os.ReadDir(dir) if err != nil { t.Fatal(err) } diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go index d58f148cb..1952a9f98 100644 --- a/pkg/runtest/run.go +++ b/pkg/runtest/run.go @@ -14,7 +14,6 @@ import ( "bufio" "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -175,7 +174,7 @@ func (ctx *Context) generatePrograms(progs chan *RunRequest) error { } func progFileList(dir, filter string) ([]string, error) { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return nil, fmt.Errorf("failed to read %v: %v", dir, err) } @@ -275,7 +274,7 @@ nextSandbox: } func parseProg(target *prog.Target, dir, filename string) (*prog.Prog, map[string]bool, *ipc.ProgInfo, error) { - data, err := ioutil.ReadFile(filepath.Join(dir, filename)) + data, err := os.ReadFile(filepath.Join(dir, filename)) if err != nil { return nil, nil, nil, fmt.Errorf("failed to read %v: %v", filename, err) } @@ -680,7 +679,7 @@ func RunTest(req *RunRequest, executor string) { } func runTestC(req *RunRequest) { - tmpDir, err := ioutil.TempDir("", "syz-runtest") + tmpDir, err := os.MkdirTemp("", "syz-runtest") if err != nil { req.Err = fmt.Errorf("failed to create temp dir: %v", err) return diff --git a/pkg/tool/flags_test.go b/pkg/tool/flags_test.go index 849e3fa00..0503c48fc 100644 --- a/pkg/tool/flags_test.go +++ b/pkg/tool/flags_test.go @@ -6,7 +6,7 @@ package tool import ( "flag" "fmt" - "io/ioutil" + "io" "strings" "testing" @@ -33,7 +33,7 @@ func TestParseFlags(t *testing.T) { t.Run(fmt.Sprint(i), func(t *testing.T) { vals := new(Values) flags := flag.NewFlagSet("", flag.ContinueOnError) - flags.SetOutput(ioutil.Discard) + flags.SetOutput(io.Discard) flags.BoolVar(&vals.Foo, "foo", false, "") flags.IntVar(&vals.Bar, "bar", 1, "") flags.StringVar(&vals.Baz, "baz", "baz", "") -- cgit mrf-deployment