From 48679d21d2d58dc0f23d4324d29505ce15b5c0e3 Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Thu, 9 Jul 2015 16:15:42 -0700 Subject: [PATCH] add boundary check before access os.Args --- pkg/kubectl/cmd/apiversions.go | 2 +- pkg/kubectl/cmd/clusterinfo.go | 2 +- pkg/kubectl/cmd/replace.go | 2 +- pkg/kubectl/cmd/rollingupdate.go | 2 +- pkg/kubectl/cmd/run.go | 2 +- pkg/kubectl/cmd/scale.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/kubectl/cmd/apiversions.go b/pkg/kubectl/cmd/apiversions.go index dc3f03f4468..b9f08a3138e 100644 --- a/pkg/kubectl/cmd/apiversions.go +++ b/pkg/kubectl/cmd/apiversions.go @@ -41,7 +41,7 @@ func NewCmdApiVersions(f *cmdutil.Factory, out io.Writer) *cobra.Command { } func RunApiVersions(f *cmdutil.Factory, out io.Writer) error { - if os.Args[1] == "apiversions" { + if len(os.Args) > 1 && os.Args[1] == "apiversions" { printDeprecationWarning("api-versions", "apiversions") } diff --git a/pkg/kubectl/cmd/clusterinfo.go b/pkg/kubectl/cmd/clusterinfo.go index 9f78e5aca62..0ebb9706349 100644 --- a/pkg/kubectl/cmd/clusterinfo.go +++ b/pkg/kubectl/cmd/clusterinfo.go @@ -46,7 +46,7 @@ func NewCmdClusterInfo(f *cmdutil.Factory, out io.Writer) *cobra.Command { } func RunClusterInfo(factory *cmdutil.Factory, out io.Writer, cmd *cobra.Command) error { - if os.Args[1] == "clusterinfo" { + if len(os.Args) > 1 && os.Args[1] == "clusterinfo" { printDeprecationWarning("cluster-info", "clusterinfo") } diff --git a/pkg/kubectl/cmd/replace.go b/pkg/kubectl/cmd/replace.go index d8489ac4c8d..2f97069a42f 100644 --- a/pkg/kubectl/cmd/replace.go +++ b/pkg/kubectl/cmd/replace.go @@ -69,7 +69,7 @@ func NewCmdReplace(f *cmdutil.Factory, out io.Writer) *cobra.Command { } func RunReplace(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string, filenames util.StringList) error { - if os.Args[1] == "update" { + if len(os.Args) > 1 && os.Args[1] == "update" { printDeprecationWarning("replace", "update") } schema, err := f.Validator() diff --git a/pkg/kubectl/cmd/rollingupdate.go b/pkg/kubectl/cmd/rollingupdate.go index 3d034db0575..45ca61e6f34 100644 --- a/pkg/kubectl/cmd/rollingupdate.go +++ b/pkg/kubectl/cmd/rollingupdate.go @@ -105,7 +105,7 @@ func validateArguments(cmd *cobra.Command, args []string) (deploymentKey, filena } func RunRollingUpdate(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error { - if os.Args[1] == "rollingupdate" { + if len(os.Args) > 1 && os.Args[1] == "rollingupdate" { printDeprecationWarning("rolling-update", "rollingupdate") } deploymentKey, filename, image, oldName, err := validateArguments(cmd, args) diff --git a/pkg/kubectl/cmd/run.go b/pkg/kubectl/cmd/run.go index 014db501298..e35d6074805 100644 --- a/pkg/kubectl/cmd/run.go +++ b/pkg/kubectl/cmd/run.go @@ -70,7 +70,7 @@ func NewCmdRun(f *cmdutil.Factory, out io.Writer) *cobra.Command { } func Run(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error { - if os.Args[1] == "run-container" { + if len(os.Args) > 1 && os.Args[1] == "run-container" { printDeprecationWarning("run", "run-container") } diff --git a/pkg/kubectl/cmd/scale.go b/pkg/kubectl/cmd/scale.go index 95c3aa837ed..996e5c143c5 100644 --- a/pkg/kubectl/cmd/scale.go +++ b/pkg/kubectl/cmd/scale.go @@ -65,7 +65,7 @@ func NewCmdScale(f *cmdutil.Factory, out io.Writer) *cobra.Command { // RunScale executes the scaling func RunScale(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error { - if os.Args[1] == "resize" { + if len(os.Args) > 1 && os.Args[1] == "resize" { printDeprecationWarning("scale", "resize") }