@@ -16,6 +16,7 @@ import (
1616 "github.com/stretchr/testify/require"
1717
1818 "github.com/NVIDIA/nvidia-container-toolkit/internal/modifier"
19+ "github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
1920 "github.com/NVIDIA/nvidia-container-toolkit/internal/test"
2021)
2122
@@ -87,8 +88,7 @@ func TestBadInput(t *testing.T) {
8788 t .Fatal (err )
8889 }
8990
90- //nolint:gosec // TODO: Can we harden this so that there is less risk of command injection
91- cmdCreate := exec .Command (nvidiaRuntime , "create" , "--bundle" )
91+ cmdCreate := exec .Command (oci .Escape1 (nvidiaRuntime ), oci .Escape ([]string {"create" , "--bundle" })... ) //nolint:gosec
9292 t .Logf ("executing: %s\n " , strings .Join (cmdCreate .Args , " " ))
9393 err = cmdCreate .Run ()
9494 require .Error (t , err , "runtime should return an error" )
@@ -105,8 +105,8 @@ func TestGoodInput(t *testing.T) {
105105 t .Fatalf ("error generating runtime spec: %v" , err )
106106 }
107107
108- //nolint:gosec // TODO: Can we harden this so that there is less risk of command injection
109- cmdRun := exec .Command (nvidiaRuntime , "run" , "--bundle" , cfg .bundlePath (), "testcontainer" )
108+ //nolint:gosec
109+ cmdRun := exec .Command (oci . Escape1 ( nvidiaRuntime ), oci . Escape ([] string { "run" , "--bundle" , cfg .bundlePath (), "testcontainer" }) ... )
110110 t .Logf ("executing: %s\n " , strings .Join (cmdRun .Args , " " ))
111111 output , err := cmdRun .CombinedOutput ()
112112 require .NoErrorf (t , err , "runtime should not return an error" , "output=%v" , string (output ))
@@ -116,8 +116,8 @@ func TestGoodInput(t *testing.T) {
116116 require .NoError (t , err , "should be no errors when reading and parsing spec from config.json" )
117117 require .Empty (t , spec .Hooks , "there should be no hooks in config.json" )
118118
119- //nolint:gosec // TODO: Can we harden this so that there is less risk of command injection
120- cmdCreate := exec .Command (nvidiaRuntime , "create" , "--bundle" , cfg .bundlePath (), "testcontainer" )
119+ //nolint:gosec
120+ cmdCreate := exec .Command (oci . Escape1 ( nvidiaRuntime ), oci . Escape ([] string { "create" , "--bundle" , cfg .bundlePath (), "testcontainer" }) ... )
121121 t .Logf ("executing: %s\n " , strings .Join (cmdCreate .Args , " " ))
122122 err = cmdCreate .Run ()
123123 require .NoError (t , err , "runtime should not return an error" )
@@ -161,8 +161,8 @@ func TestDuplicateHook(t *testing.T) {
161161 }
162162
163163 // Test how runtime handles already existing prestart hook in config.json
164- //nolint:gosec // TODO: Can we harden this so that there is less risk of command injection
165- cmdCreate := exec .Command (nvidiaRuntime , "create" , "--bundle" , cfg .bundlePath (), "testcontainer" )
164+ //nolint:gosec
165+ cmdCreate := exec .Command (oci . Escape1 ( nvidiaRuntime ), oci . Escape ([] string { "create" , "--bundle" , cfg .bundlePath (), "testcontainer" }) ... )
166166 t .Logf ("executing: %s\n " , strings .Join (cmdCreate .Args , " " ))
167167 output , err := cmdCreate .CombinedOutput ()
168168 require .NoErrorf (t , err , "runtime should not return an error" , "output=%v" , string (output ))
@@ -230,8 +230,8 @@ func (c testConfig) generateNewRuntimeSpec() error {
230230 return err
231231 }
232232
233- //nolint:gosec // TODO: Can we harden this so that there is less risk of command injection
234- cmd := exec .Command ("cp" , c .unmodifiedSpecFile (), c .specFilePath ())
233+ //nolint:gosec
234+ cmd := exec .Command (oci . Escape1 ( "cp" ), oci . Escape ([] string { c .unmodifiedSpecFile (), c .specFilePath ()}) ... )
235235 err = cmd .Run ()
236236 if err != nil {
237237 return err
0 commit comments