Skip to content

fix(ssh): bind ssh.task_definition to sshCmd's own flag#42

Open
SAY-5 wants to merge 1 commit into
springload:masterfrom
SAY-5:fix/ssh-bindpflag-nil-panic-41
Open

fix(ssh): bind ssh.task_definition to sshCmd's own flag#42
SAY-5 wants to merge 1 commit into
springload:masterfrom
SAY-5:fix/ssh-bindpflag-nil-panic-41

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 23, 2026

Fixes #41.

Problem

cmd/ssh.go binds ssh.task_definition to runCmd's task_definition flag:

sshCmd.PersistentFlags().StringP("task_definition", ...)
viper.BindPFlag("ssh.task_definition", runCmd.PersistentFlags().Lookup("task_definition"))

But runCmd doesn't define task_definition, its BindPFlag call is commented out in cmd/run.go:58. Lookup returns a nil *pflag.Flag, viper.BindPFlag silently stores the nil binding, and the first viper.Get("ssh.task_definition") in the command path panics inside pflagValue.HasChanged:

panic: runtime error: invalid memory address or nil pointer dereference
github.com/spf13/viper.pflagValue.HasChanged flags.go:41
github.com/spf13/viper.(*Viper).find viper.go:914
github.com/springload/ecs-tool/cmd.glob..func9 ssh.go:26

This crashes ecs-tool ssh on any invocation (v1.9.8 regression, v1.9.7 works).

Fix

Bind to sshCmd's own PersistentFlags, which is where the flag is actually registered two lines above.

Test

go build ./... and go vet ./cmd/... clean. Package has no existing tests; the regression is that running the ssh subcommand no longer panics.

cmd/ssh.go bound ssh.task_definition to runCmd.PersistentFlags().Lookup("task_definition").
runCmd does not define task_definition (its BindPFlag line is
commented out in cmd/run.go), so the Lookup returned a nil
*pflag.Flag. viper.BindPFlag silently stored the nil binding, and
the first viper.Get("ssh.task_definition") in the command path
panicked inside pflagValue.HasChanged — crashing 'ecs-tool ssh'
with:

    panic: runtime error: invalid memory address or nil pointer dereference
    viper.pflagValue.HasChanged flags.go:41
    viper.(*Viper).find viper.go:914
    cmd.glob..func9 ssh.go:26

Bind to sshCmd's own PersistentFlags, which is where the flag is
actually registered two lines above.

Refs springload/ecs-tool issue 41.
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 this pull request may close these issues.

runtime error: invalid memory address or nil pointer dereference

1 participant