From 1f498c5ff021a3255a28f0df35ca46adfc248e6c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 10 Dec 2025 13:40:44 +0100 Subject: [PATCH] fix linting issues Some false positives from gosec (G602: slice index out of range) integration-cli/daemon/daemon.go:109:1: deprecatedComment: `Deprecated: ` notices should be in a dedicated paragraph, separated from the rest (gocritic) // Deprecated: use cli.WaitCmd instead ^ integration-cli/docker_cli_build_test.go:562:3: dupOption: function argument `build.WithFile("test_file3", "test3")` is duplicated (gocritic) build.WithFile("test_file3", "test3"), ^ integration-cli/docker_utils_test.go:250:1: deprecatedComment: `Deprecated: ` notices should be in a dedicated paragraph, separated from the rest (gocritic) // Deprecated: use cli.WaitFor ^ daemon/libnetwork/ipams/defaultipam/address_space.go:45:39: G602: slice index out of range (gosec) if predefined[j].Overlaps(predefined[i].Base) { ^ daemon/libnetwork/ipams/defaultipam/address_space.go:49:29: G602: slice index out of range (gosec) predefined[j] = predefined[i] ^ daemon/libnetwork/libnetwork_linux_test.go:1492:9: G602: slice index out of range (gosec) sboxes[thd-1], err = controller.NewSandbox(context.Background(), fmt.Sprintf("%drace", thd)) ^ daemon/libnetwork/networkdb/cluster_test.go:111:21: G602: slice index out of range (gosec) mean, stdev := nf[0], nf[1] ^ daemon/libnetwork/osl/interface_linux.go:586:54: G602: slice index out of range (gosec) log.G(ctx).WithField("portState", stateFileContent[0]).Debug("waiting for bridge port to be forwarding") ^ daemon/libnetwork/osl/interface_linux.go:594:32: G602: slice index out of range (gosec) "portState": stateFileContent[0], ^ daemon/libnetwork/portallocator/osallocator_linux_test.go:358:13: G602: slice index out of range (gosec) if payload[0] != 0x1 { ^ daemon/libnetwork/portallocator/osallocator_linux_test.go:359:68: G602: slice index out of range (gosec) readCh <- fmt.Errorf("expected payload 0x1, but got %x", payload[0]) ^ daemon/logger/gelf/gelf_test.go:197:9: nilness: impossible condition: nil != nil (govet) if err != nil { ^ Signed-off-by: Sebastiaan van Stijn --- daemon/logger/gelf/gelf_test.go | 2 +- integration-cli/daemon/daemon.go | 1 + integration-cli/docker_cli_build_test.go | 4 ++-- integration-cli/docker_cli_daemon_test.go | 4 ++-- integration-cli/docker_utils_test.go | 1 + 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/daemon/logger/gelf/gelf_test.go b/daemon/logger/gelf/gelf_test.go index 32d6175639..ab1f377eef 100644 --- a/daemon/logger/gelf/gelf_test.go +++ b/daemon/logger/gelf/gelf_test.go @@ -193,7 +193,7 @@ func TestNewGELFUDPWriter(t *testing.T) { if err != nil { t.Fatal(err) } - writer.Close() + err = writer.Close() if err != nil { t.Fatal(err) } diff --git a/integration-cli/daemon/daemon.go b/integration-cli/daemon/daemon.go index a9de8df8d4..4919c7ebb0 100644 --- a/integration-cli/daemon/daemon.go +++ b/integration-cli/daemon/daemon.go @@ -106,6 +106,7 @@ func (d *Daemon) WaitRun(contID string) error { } // WaitInspectWithArgs waits for the specified expression to be equals to the specified expected string in the given time. +// // Deprecated: use cli.WaitCmd instead func WaitInspectWithArgs(dockerBinary, name, expr, expected string, timeout time.Duration, arg ...string) error { after := time.After(timeout) diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 343ddc9900..c4ef36b262 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -560,8 +560,8 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' build.WithFile("test_file1", "test1"), build.WithFile("test_file2", "test2"), build.WithFile("test_file3", "test3"), - build.WithFile("test_file3", "test3"), - build.WithFile("test_file4", "test4"))) + build.WithFile("test_file4", "test4"), + )) } // These tests are mainly for user namespaces to verify that new directories diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 98b59a762a..e8dd08260f 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -178,7 +178,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartOnFailure(c *testing.T) { // wait test1 to stop hostArgs := []string{"--host", s.d.Sock()} - err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 10*time.Second, hostArgs...) + err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 10*time.Second, hostArgs...) //nolint:staticcheck // TODO WaitInspectWithArgs is deprecated. assert.NilError(c, err, "test1 should exit but not") // record last start time @@ -189,7 +189,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartOnFailure(c *testing.T) { s.d.Restart(c) // test1 shouldn't restart at all - err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 0, hostArgs...) + err = daemon.WaitInspectWithArgs(dockerBinary, "test1", "{{.State.Running}} {{.State.Restarting}}", "false false", 0, hostArgs...) //nolint:staticcheck // TODO WaitInspectWithArgs is deprecated. assert.NilError(c, err, "test1 should exit but not") // make sure test1 isn't restarted when daemon restart diff --git a/integration-cli/docker_utils_test.go b/integration-cli/docker_utils_test.go index 5b25312bf0..6dfa14b0be 100644 --- a/integration-cli/docker_utils_test.go +++ b/integration-cli/docker_utils_test.go @@ -247,6 +247,7 @@ func appendBaseEnv(isTLS bool, env ...string) []string { // waitInspect will wait for the specified container to have the specified string // in the inspect output. It will wait until the specified timeout (in seconds) // is reached. +// // Deprecated: use cli.WaitFor func waitInspect(name, expr, expected string, timeout time.Duration) error { return daemon.WaitInspectWithArgs(dockerBinary, name, expr, expected, timeout)