summaryrefslogtreecommitdiff
path: root/cmd/podman/cliconfig
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-04-15 09:53:38 -0500
committerbaude <bbaude@redhat.com>2019-04-15 12:21:51 -0500
commit6fb0a706af438778dd372d4b05b417fb30a45965 (patch)
treed1ba6e427d8524630ceb1c82eaec92c91b061e6f /cmd/podman/cliconfig
parent6e1dab76e2282774d384ec3bc46e314e9b030595 (diff)
downloadpodman-6fb0a706af438778dd372d4b05b417fb30a45965.tar.gz
podman-6fb0a706af438778dd372d4b05b417fb30a45965.tar.bz2
podman-6fb0a706af438778dd372d4b05b417fb30a45965.zip
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 <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/cliconfig')
-rw-r--r--cmd/podman/cliconfig/commands.go36
-rw-r--r--cmd/podman/cliconfig/config.go1
2 files changed, 28 insertions, 9 deletions
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 {