Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty Executor Config will cause invalid memory address or nil pointer dereference in SHELL Executor #945

Closed
yinyajun opened this issue Apr 27, 2021 · 0 comments · Fixed by #948

Comments

@yinyajun
Copy link

Describe the bug

In a new job, I set executor=shell, but forgot to set executor_config.
When this job executes, it will cause invalid memory address or nil pointer dereference and panics dkron agent.

To Reproduce
Steps to reproduce the behavior:

  1. add a new job
  2. set executor=shell
  3. leave executor_config blank
  4. run this job

Expected behavior
Empty Executor Config in a job should do nothing and will not panics dkron agent

Bug
In dkron/builtin/bins/dkron-executor-shell/shell.go, Line 150-176:

// Determine the shell invocation based on OS
func buildCmd(command string, useShell bool, env []string, cwd string) (cmd *exec.Cmd, err error) {
	var shell, flag string

	if useShell {
		if runtime.GOOS == windows {
			shell = "cmd"
			flag = "/C"
		} else {
			shell = "/bin/sh"
			flag = "-c"
		}
		cmd = exec.Command(shell, flag, command)
	} else {
		args, err := shellwords.Parse(command)
		if err != nil {
			return nil, err
		}
		cmd = exec.Command(args[0], args[1:]...)
	}
	if env != nil {
		cmd.Env = append(os.Environ(), env...)
	}
	cmd.Dir = cwd
	return
}

if command is an empty string, then args is a empty array.

args[0] and args[1:] will out of array bounds and cause invalid memory address or nil pointer dereference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant