Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible panics in slice type assertion #1049

Merged
merged 1 commit into from Jan 26, 2020

Conversation

saschagrunert
Copy link
Member

What type of PR is this?

  • bug
  • cleanup
  • documentation
  • feature

What this PR does / why we need it:

Before accessing the slices .Value() we should type check that it is
that actual type, otherwise we will end-up in a panic.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

None

Testing

Reproducer:

package main

import (
	"os"

	"github.com/urfave/cli/v2"
)

func main() {
	app := cli.NewApp()
	app.Flags = []cli.Flag{&cli.StringFlag{Name: "test"}}
	app.Action = func(ctx *cli.Context) error {
		ctx.StringSlice("test")
		return nil
	}
	if err := app.Run(os.Args); err != nil {
		os.Exit(1)
	}
}

Release Notes

- Fixed possible runtime panic in slice parsing

Before accessing the slices `.Value()` we should type check that it is
that actual type, otherwise we will end-up in a panic.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
@saschagrunert saschagrunert requested a review from a team as a code owner January 22, 2020 11:40
@saschagrunert saschagrunert requested review from rliebz and coilysiren and removed request for a team January 22, 2020 11:40
@codecov
Copy link

codecov bot commented Jan 22, 2020

Codecov Report

Merging #1049 into master will increase coverage by 0.23%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1049      +/-   ##
==========================================
+ Coverage    72.6%   72.83%   +0.23%     
==========================================
  Files          33       33              
  Lines        2482     2474       -8     
==========================================
  Hits         1802     1802              
+ Misses        569      565       -4     
+ Partials      111      107       -4
Impacted Files Coverage Δ
flag_int64_slice.go 78.33% <100%> (+2.52%) ⬆️
flag_int_slice.go 74.62% <100%> (+2.16%) ⬆️
flag_float64_slice.go 57.14% <100%> (+1.75%) ⬆️
flag_string_slice.go 79.66% <100%> (+2.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f1a114a...ca666ae. Read the comment docs.

Copy link
Member

@rliebz rliebz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks for this!

@asahasrabuddhe
Copy link
Member

Looks good to me 👍

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.

None yet

3 participants