mirror of https://github.com/docker/cli.git
Fix #1113 "Segfault on --help with --tlsverify if no ca certificate is present"
Errors were not checked while initializing the docker client in the help command Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
This commit is contained in:
parent
001c8f2f7f
commit
f4b0780e20
|
@ -83,7 +83,9 @@ func setFlagErrorFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *p
|
||||||
// is called.
|
// is called.
|
||||||
flagErrorFunc := cmd.FlagErrorFunc()
|
flagErrorFunc := cmd.FlagErrorFunc()
|
||||||
cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
|
cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
|
||||||
initializeDockerCli(dockerCli, flags, opts)
|
if err := initializeDockerCli(dockerCli, flags, opts); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := isSupported(cmd, dockerCli); err != nil {
|
if err := isSupported(cmd, dockerCli); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -94,7 +96,10 @@ func setFlagErrorFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *p
|
||||||
func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.FlagSet, opts *cliflags.ClientOptions) {
|
func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.FlagSet, opts *cliflags.ClientOptions) {
|
||||||
defaultHelpFunc := cmd.HelpFunc()
|
defaultHelpFunc := cmd.HelpFunc()
|
||||||
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
||||||
initializeDockerCli(dockerCli, flags, opts)
|
if err := initializeDockerCli(dockerCli, flags, opts); err != nil {
|
||||||
|
ccmd.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
if err := isSupported(ccmd, dockerCli); err != nil {
|
if err := isSupported(ccmd, dockerCli); err != nil {
|
||||||
ccmd.Println(err)
|
ccmd.Println(err)
|
||||||
return
|
return
|
||||||
|
@ -123,7 +128,9 @@ func setValidateArgs(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pf
|
||||||
|
|
||||||
cmdArgs := ccmd.Args
|
cmdArgs := ccmd.Args
|
||||||
ccmd.Args = func(cmd *cobra.Command, args []string) error {
|
ccmd.Args = func(cmd *cobra.Command, args []string) error {
|
||||||
initializeDockerCli(dockerCli, flags, opts)
|
if err := initializeDockerCli(dockerCli, flags, opts); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := isSupported(cmd, dockerCli); err != nil {
|
if err := isSupported(cmd, dockerCli); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -132,13 +139,15 @@ func setValidateArgs(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pf
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeDockerCli(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *cliflags.ClientOptions) {
|
func initializeDockerCli(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *cliflags.ClientOptions) error {
|
||||||
if dockerCli.Client() == nil { // when using --help, PersistentPreRun is not called, so initialization is needed.
|
if dockerCli.Client() != nil {
|
||||||
// flags must be the top-level command flags, not cmd.Flags()
|
return nil
|
||||||
opts.Common.SetDefaultOptions(flags)
|
|
||||||
dockerPreRun(opts)
|
|
||||||
dockerCli.Initialize(opts)
|
|
||||||
}
|
}
|
||||||
|
// when using --help, PersistentPreRun is not called, so initialization is needed.
|
||||||
|
// flags must be the top-level command flags, not cmd.Flags()
|
||||||
|
opts.Common.SetDefaultOptions(flags)
|
||||||
|
dockerPreRun(opts)
|
||||||
|
return dockerCli.Initialize(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// visitAll will traverse all commands from the root.
|
// visitAll will traverse all commands from the root.
|
||||||
|
|
Loading…
Reference in New Issue