From 00d13b9daca374f7e0be26cefd23b9a2846e48d9 Mon Sep 17 00:00:00 2001 From: Sohan Kunkerkar Date: Tue, 8 Dec 2020 18:24:30 -0500 Subject: [PATCH] *: fix errcheck warnings --- internal/exec/stages/disks/luks.go | 4 +- internal/exec/stages/disks/partitions.go | 4 +- internal/exec/util/passwd.go | 2 +- internal/exec/util/user_group_lookup_test.go | 5 ++- tests/filesystem.go | 6 ++- tests/negative/security/tls.go | 4 +- tests/negative/timeouts/timeouts.go | 6 +-- tests/positive/proxy/http.go | 2 +- tests/positive/security/tls.go | 4 +- tests/servers/servers.go | 42 +++++++++++--------- 10 files changed, 46 insertions(+), 33 deletions(-) diff --git a/internal/exec/stages/disks/luks.go b/internal/exec/stages/disks/luks.go index dbd30d3874..9626bf9653 100644 --- a/internal/exec/stages/disks/luks.go +++ b/internal/exec/stages/disks/luks.go @@ -110,7 +110,9 @@ func (s *stage) createLuks(config types.Config) error { var ignitionCreatedKeyFile bool // create keyfile inside of tmpfs, it will be copied to the // sysroot by the files stage - os.MkdirAll(distro.LuksInitramfsKeyFilePath(), 0700) + if err := os.MkdirAll(distro.LuksInitramfsKeyFilePath(), 0700); err != nil { + return fmt.Errorf("creating directory for keyfile: %v", err) + } keyFilePath := filepath.Join(distro.LuksInitramfsKeyFilePath(), luks.Name) devAlias := execUtil.DeviceAlias(*luks.Device) if util.NilOrEmpty(luks.KeyFile.Source) { diff --git a/internal/exec/stages/disks/partitions.go b/internal/exec/stages/disks/partitions.go index 330ca2789b..bdfe83dbac 100644 --- a/internal/exec/stages/disks/partitions.go +++ b/internal/exec/stages/disks/partitions.go @@ -322,7 +322,9 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error { op := sgdisk.Begin(s.Logger, devAlias) s.Logger.Info("wiping partition table requested on %q", devAlias) op.WipeTable(true) - op.Commit() + if err := op.Commit(); err != nil { + return err + } } // Ensure all partitions with number 0 are last diff --git a/internal/exec/util/passwd.go b/internal/exec/util/passwd.go index c6af9ccb21..226eaf52e5 100644 --- a/internal/exec/util/passwd.go +++ b/internal/exec/util/passwd.go @@ -218,7 +218,7 @@ func (u Util) AuthorizeSSHKeys(c types.PasswdUser) error { if err != nil { return fmt.Errorf("failed to set SSH key: %v", err) } - journal.Send(fmt.Sprintf("wrote ssh authorized keys file for user: %s", c.Name), journal.PriInfo, map[string]string{ + _ = journal.Send(fmt.Sprintf("wrote ssh authorized keys file for user: %s", c.Name), journal.PriInfo, map[string]string{ "IGNITION_USER_NAME": c.Name, "IGNITION_PATH": path, "MESSAGE_ID": ignitionSSHAuthorizedkeysMessageID, diff --git a/internal/exec/util/user_group_lookup_test.go b/internal/exec/util/user_group_lookup_test.go index b1fb096f90..48fa6a43f6 100644 --- a/internal/exec/util/user_group_lookup_test.go +++ b/internal/exec/util/user_group_lookup_test.go @@ -63,7 +63,10 @@ func TestUserLookup(t *testing.T) { // perform a user lookup to ensure libnss_files.so is loaded // note this assumes /etc/nsswitch.conf invokes files. - user.Lookup("root") + _, err := user.Lookup("root") + if err != nil { + t.Fatalf("libnss_files.so is not loaded: %v", err) + } td, err := tempBase() if err != nil { diff --git a/tests/filesystem.go b/tests/filesystem.go index e1a570fe5d..d4835515b6 100644 --- a/tests/filesystem.go +++ b/tests/filesystem.go @@ -224,7 +224,7 @@ func setupDisk(ctx context.Context, disk *types.Disk, diskIndex int, imageSize i loopdev := disk.Device defer func() { if err != nil { - destroyDevice(loopdev) + _ = destroyDevice(loopdev) } }() @@ -470,7 +470,9 @@ func createFilesFromSlice(basedir string, files []types.File) error { } writer.Flush() } - os.Chown(filepath.Join(basedir, file.Directory, file.Name), file.User, file.Group) + if err := os.Chown(filepath.Join(basedir, file.Directory, file.Name), file.User, file.Group); err != nil { + return err + } } return nil } diff --git a/tests/negative/security/tls.go b/tests/negative/security/tls.go index 16f1c2ed38..0df69e7b24 100644 --- a/tests/negative/security/tls.go +++ b/tests/negative/security/tls.go @@ -74,10 +74,10 @@ var ( }`) customCAServer = httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write(customCAServerFile) + _, _ = w.Write(customCAServerFile) })) customCAServer2 = httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write(customCAServerFile2) + _, _ = w.Write(customCAServerFile2) })) ) diff --git a/tests/negative/timeouts/timeouts.go b/tests/negative/timeouts/timeouts.go index 462c3eba80..5ac0967ba4 100644 --- a/tests/negative/timeouts/timeouts.go +++ b/tests/negative/timeouts/timeouts.go @@ -44,7 +44,7 @@ var ( time.Sleep(time.Second * 2) // Give a config that merges ourselves and sets the timeouts to 1 // second (less than we wait!) - w.Write([]byte(fmt.Sprintf(`{ + _, _ = w.Write([]byte(fmt.Sprintf(`{ "ignition": { "version": "$version", "config": { @@ -161,7 +161,7 @@ func AppendNoneThenLowerHTTPTimeouts() types.Test { time.Sleep(time.Second * 2) // Give a config that merges ourselves and sets the timeouts to 1 // second (less than we wait!) - w.Write([]byte(`{ + _, _ = w.Write([]byte(`{ "ignition": { "version": "$version" } @@ -171,7 +171,7 @@ func AppendNoneThenLowerHTTPTimeouts() types.Test { configNoDelayServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Give a config that merges ourselves and sets the timeouts to 1 // second (less than we wait!) - w.Write([]byte(fmt.Sprintf(`{ + _, _ = w.Write([]byte(fmt.Sprintf(`{ "ignition": "version": "$version", "config": { diff --git a/tests/positive/proxy/http.go b/tests/positive/proxy/http.go index bdf6d20d2c..1863c744e0 100644 --- a/tests/positive/proxy/http.go +++ b/tests/positive/proxy/http.go @@ -25,7 +25,7 @@ import ( var ( proxyServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(ignConfig)) + _, _ = w.Write([]byte(ignConfig)) })) mockConfigURL = "http://www.fake.tld" diff --git a/tests/positive/security/tls.go b/tests/positive/security/tls.go index e67fab9b57..0b52d78435 100644 --- a/tests/positive/security/tls.go +++ b/tests/positive/security/tls.go @@ -78,10 +78,10 @@ var ( }`) customCAServer = httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write(customCAServerFile) + _, _ = w.Write(customCAServerFile) })) customCAServer2 = httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write(customCAServerFile2) + _, _ = w.Write(customCAServerFile2) })) ) diff --git a/tests/servers/servers.go b/tests/servers/servers.go index ba32b245ef..8f0f5e3f6d 100644 --- a/tests/servers/servers.go +++ b/tests/servers/servers.go @@ -61,19 +61,19 @@ fdsa`) // HTTP Server func (server *HTTPServer) Config(w http.ResponseWriter, r *http.Request) { - w.Write(servedConfig) + _, _ = w.Write(servedConfig) } func (server *HTTPServer) Contents(w http.ResponseWriter, r *http.Request) { - w.Write(servedContents) + _, _ = w.Write(servedContents) } func (server *HTTPServer) Certificates(w http.ResponseWriter, r *http.Request) { - w.Write(fixtures.PublicKey) + _, _ = w.Write(fixtures.PublicKey) } func (server *HTTPServer) CABundle(w http.ResponseWriter, r *http.Request) { - w.Write(fixtures.CABundle) + _, _ = w.Write(fixtures.CABundle) } func compress(contents []byte) []byte { @@ -89,20 +89,20 @@ func compress(contents []byte) []byte { } func (server *HTTPServer) ConfigCompressed(w http.ResponseWriter, r *http.Request) { - w.Write(compress(servedConfig)) + _, _ = w.Write(compress(servedConfig)) } func (server *HTTPServer) ContentsCompressed(w http.ResponseWriter, r *http.Request) { - w.Write(compress(servedContents)) + _, _ = w.Write(compress(servedContents)) } func (server *HTTPServer) CertificatesCompressed(w http.ResponseWriter, r *http.Request) { - w.Write(compress(fixtures.PublicKey)) + _, _ = w.Write(compress(fixtures.PublicKey)) } func errorHandler(w http.ResponseWriter, message string) { w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(message)) + _, _ = w.Write([]byte(message)) } // headerCheck validates that all required headers are present @@ -161,19 +161,19 @@ func overwrittenHeaderCheck(w http.ResponseWriter, r *http.Request) { func (server *HTTPServer) ConfigHeaders(w http.ResponseWriter, r *http.Request) { headerCheck(w, r) - w.Write(servedConfig) + _, _ = w.Write(servedConfig) } func (server *HTTPServer) ContentsHeaders(w http.ResponseWriter, r *http.Request) { headerCheck(w, r) - w.Write(servedContents) + _, _ = w.Write(servedContents) } func (server *HTTPServer) CertificatesHeaders(w http.ResponseWriter, r *http.Request) { headerCheck(w, r) - w.Write(fixtures.PublicKey) + _, _ = w.Write(fixtures.PublicKey) } // redirectedHeaderCheck validates that user's headers from the original request are missing @@ -198,7 +198,7 @@ func (server *HTTPServer) ConfigRedirect(w http.ResponseWriter, r *http.Request) func (server *HTTPServer) ConfigRedirected(w http.ResponseWriter, r *http.Request) { redirectedHeaderCheck(w, r) - w.Write(servedConfig) + _, _ = w.Write(servedConfig) } // ContentsRedirect redirects the request to ContentsRedirected @@ -210,7 +210,7 @@ func (server *HTTPServer) ContentsRedirect(w http.ResponseWriter, r *http.Reques func (server *HTTPServer) ContentsRedirected(w http.ResponseWriter, r *http.Request) { redirectedHeaderCheck(w, r) - w.Write(servedContents) + _, _ = w.Write(servedContents) } // CertificatesRedirect redirects the request to CertificatesRedirected @@ -222,25 +222,25 @@ func (server *HTTPServer) CertificatesRedirect(w http.ResponseWriter, r *http.Re func (server *HTTPServer) CertificatesRedirected(w http.ResponseWriter, r *http.Request) { redirectedHeaderCheck(w, r) - w.Write(fixtures.PublicKey) + _, _ = w.Write(fixtures.PublicKey) } func (server *HTTPServer) ConfigHeadersOverwrite(w http.ResponseWriter, r *http.Request) { overwrittenHeaderCheck(w, r) - w.Write(servedConfig) + _, _ = w.Write(servedConfig) } func (server *HTTPServer) ContentsHeadersOverwrite(w http.ResponseWriter, r *http.Request) { overwrittenHeaderCheck(w, r) - w.Write(servedContents) + _, _ = w.Write(servedContents) } func (server *HTTPServer) CertificatesHeadersOverwrite(w http.ResponseWriter, r *http.Request) { overwrittenHeaderCheck(w, r) - w.Write(fixtures.PublicKey) + _, _ = w.Write(fixtures.PublicKey) } type HTTPServer struct{} @@ -266,7 +266,9 @@ func (server *HTTPServer) Start() { http.HandleFunc("/config_headers_overwrite", server.ConfigHeadersOverwrite) http.HandleFunc("/caBundle", server.CABundle) s := &http.Server{Addr: ":8080"} - go s.ListenAndServe() + go func() { + _ = s.ListenAndServe() + }() } // TFTP Server @@ -293,5 +295,7 @@ type TFTPServer struct{} func (server *TFTPServer) Start() { s := tftp.NewServer(server.ReadHandler, nil) s.SetTimeout(5 * time.Second) - go s.ListenAndServe(":69") + go func() { + _ = s.ListenAndServe(":69") + }() }