Skip to content

Commit

Permalink
Add error returns if command invalid in RunCommand in-toto#124
Browse files Browse the repository at this point in the history
u5surf committed Sep 11, 2021
1 parent 02b98c8 commit bfa1d8e
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions in_toto/runlib.go
Original file line number Diff line number Diff line change
@@ -240,6 +240,10 @@ command execution.
*/
func RunCommand(cmdArgs []string, runDir string) (map[string]interface{}, error) {

if cmdArgs == nil || len(cmdArgs) == 0 {
return nil, errors.New("invalid command")
}

cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)

if runDir != "" {
2 changes: 2 additions & 0 deletions in_toto/runlib_test.go
Original file line number Diff line number Diff line change
@@ -447,6 +447,8 @@ func TestInTotoRun(t *testing.T) {
KeyVal: KeyVal{},
Scheme: "",
}, []string{"sha256"}},
{[]string{"alice.pub"}, []string{}, nil, validKey, []string{"sha256"}},
{[]string{"alice.pub"}, []string{"foo.tar.gz"}, nil, validKey, []string{"sha256"}},
}

for _, table := range tablesInvalid {

0 comments on commit bfa1d8e

Please sign in to comment.