From 6fb0a706af438778dd372d4b05b417fb30a45965 Mon Sep 17 00:00:00 2001 From: baude Date: Mon, 15 Apr 2019 09:53:38 -0500 Subject: Fix segfaults attribute to missing options In cases where the remote client culls options to a command, we need to be sure that the lookup for that flag does not result in a nil pointer. To do so, we add a Remote attribute to the podman struct and then cli helper funcs are now aware they are remote. Signed-off-by: baude --- cmd/podman/cliconfig/commands.go | 36 +++++++++++++++++++++++++++--------- cmd/podman/cliconfig/config.go | 1 + 2 files changed, 28 insertions(+), 9 deletions(-) (limited to 'cmd/podman/cliconfig') diff --git a/cmd/podman/cliconfig/commands.go b/cmd/podman/cliconfig/commands.go index 00b66e32a..f6d92611f 100644 --- a/cmd/podman/cliconfig/commands.go +++ b/cmd/podman/cliconfig/commands.go @@ -26,7 +26,9 @@ func (p *PodmanCommand) IsSet(opt string) bool { func (p *PodmanCommand) Bool(opt string) bool { flag := p.Flags().Lookup(opt) if flag == nil { - logrus.Errorf("Could not find flag %s", opt) + if !p.Remote { + logrus.Errorf("Could not find flag %s", opt) + } return false } val, err := p.Flags().GetBool(opt) @@ -40,7 +42,9 @@ func (p *PodmanCommand) Bool(opt string) bool { func (p *PodmanCommand) String(opt string) string { flag := p.Flags().Lookup(opt) if flag == nil { - logrus.Errorf("Could not find flag %s", opt) + if !p.Remote { + logrus.Errorf("Could not find flag %s", opt) + } return "" } val, err := p.Flags().GetString(opt) @@ -54,7 +58,9 @@ func (p *PodmanCommand) String(opt string) string { func (p *PodmanCommand) StringArray(opt string) []string { flag := p.Flags().Lookup(opt) if flag == nil { - logrus.Errorf("Could not find flag %s", opt) + if !p.Remote { + logrus.Errorf("Could not find flag %s", opt) + } return []string{} } val, err := p.Flags().GetStringArray(opt) @@ -68,7 +74,9 @@ func (p *PodmanCommand) StringArray(opt string) []string { func (p *PodmanCommand) StringSlice(opt string) []string { flag := p.Flags().Lookup(opt) if flag == nil { - logrus.Errorf("Could not find flag %s", opt) + if !p.Remote { + logrus.Errorf("Could not find flag %s", opt) + } return []string{} } val, err := p.Flags().GetStringSlice(opt) @@ -82,7 +90,9 @@ func (p *PodmanCommand) StringSlice(opt string) []string { func (p *PodmanCommand) Int(opt string) int { flag := p.Flags().Lookup(opt) if flag == nil { - logrus.Errorf("Could not find flag %s", opt) + if !p.Remote { + logrus.Errorf("Could not find flag %s", opt) + } return 0 } val, err := p.Flags().GetInt(opt) @@ -96,7 +106,9 @@ func (p *PodmanCommand) Int(opt string) int { func (p *PodmanCommand) Uint(opt string) uint { flag := p.Flags().Lookup(opt) if flag == nil { - logrus.Errorf("Could not find flag %s", opt) + if !p.Remote { + logrus.Errorf("Could not find flag %s", opt) + } return 0 } val, err := p.Flags().GetUint(opt) @@ -110,7 +122,9 @@ func (p *PodmanCommand) Uint(opt string) uint { func (p *PodmanCommand) Int64(opt string) int64 { flag := p.Flags().Lookup(opt) if flag == nil { - logrus.Errorf("Could not find flag %s", opt) + if !p.Remote { + logrus.Errorf("Could not find flag %s", opt) + } return 0 } val, err := p.Flags().GetInt64(opt) @@ -124,7 +138,9 @@ func (p *PodmanCommand) Int64(opt string) int64 { func (p *PodmanCommand) Uint64(opt string) uint64 { flag := p.Flags().Lookup(opt) if flag == nil { - logrus.Errorf("Could not find flag %s", opt) + if !p.Remote { + logrus.Errorf("Could not find flag %s", opt) + } return 0 } val, err := p.Flags().GetUint64(opt) @@ -138,7 +154,9 @@ func (p *PodmanCommand) Uint64(opt string) uint64 { func (p *PodmanCommand) Float64(opt string) float64 { flag := p.Flags().Lookup(opt) if flag == nil { - logrus.Errorf("Could not find flag %s", opt) + if !p.Remote { + logrus.Errorf("Could not find flag %s", opt) + } return 0 } val, err := p.Flags().GetFloat64(opt) diff --git a/cmd/podman/cliconfig/config.go b/cmd/podman/cliconfig/config.go index 2692ace36..982c77c17 100644 --- a/cmd/podman/cliconfig/config.go +++ b/cmd/podman/cliconfig/config.go @@ -8,6 +8,7 @@ type PodmanCommand struct { *cobra.Command InputArgs []string GlobalFlags MainFlags + Remote bool } type MainFlags struct { -- cgit v1.2.3-54-g00ecf