From 5ab7604404a293b05b7b8167c100519f2147c718 Mon Sep 17 00:00:00 2001 From: Yuri van Oers Date: Thu, 29 Apr 2021 00:12:00 +0200 Subject: [PATCH] Fix shell executor crashing on missing command --- builtin/bins/dkron-executor-shell/shell.go | 3 +++ builtin/bins/dkron-executor-shell/shell_test.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/builtin/bins/dkron-executor-shell/shell.go b/builtin/bins/dkron-executor-shell/shell.go index e3978c0cc..3d4da4bef 100644 --- a/builtin/bins/dkron-executor-shell/shell.go +++ b/builtin/bins/dkron-executor-shell/shell.go @@ -165,6 +165,9 @@ func buildCmd(command string, useShell bool, env []string, cwd string) (cmd *exe if err != nil { return nil, err } + if len(args) == 0 { + return nil, errors.New("shell: Command missing") + } cmd = exec.Command(args[0], args[1:]...) } if env != nil { diff --git a/builtin/bins/dkron-executor-shell/shell_test.go b/builtin/bins/dkron-executor-shell/shell_test.go index f93520408..039077564 100644 --- a/builtin/bins/dkron-executor-shell/shell_test.go +++ b/builtin/bins/dkron-executor-shell/shell_test.go @@ -7,6 +7,10 @@ import ( "github.com/stretchr/testify/assert" ) +func Test_buildCmdInvalidInput(t *testing.T) { + assert.NotPanics(t, func() { buildCmd("", false, []string{}, "") }) +} + func Test_buildCmd(t *testing.T) { // test shell command