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

recursiveGet: switch on line 19 falls through to a guaranteed index out of range panic #1

Open
eloff opened this issue Sep 3, 2017 · 4 comments

Comments

@eloff
Copy link

eloff commented Sep 3, 2017

If we enter this switch, len(path) == 0. However, if none of the conditions match (e.g. data is an int) then it falls through to path[0] which will panic with index out of range. I recommend adding a default case to the switch or after the switch to return an informative error.

if len(path) == 0 {
	switch data.(type) {
	case string:
		return data.(string)
	case float64:
		return data.(float64)
	case bool:
		return data.(bool)
	case nil:
		return nil
	case []interface{}:
		return data
	case map[string]interface{}:
		return data
	}
}

switch path[0].(type) {
@yasuyuky
Copy link
Owner

(e.g. data is an int)

I think data can never be an int.

@eloff
Copy link
Author

eloff commented Jun 10, 2018

data was actually an int for me, and I modified the library as described to work around it. Perhaps I was using the library in a way not intended, but either way the fix won't do any harm.

@yasuyuky
Copy link
Owner

yasuyuky commented Jun 10, 2018

Do you have any example for this case?

@yasuyuky yasuyuky reopened this Jun 10, 2018
@eloff
Copy link
Author

eloff commented Jun 17, 2018

No, I no longer have access to the codebase, and we switched away from this library in the end.

My gut feeling is the "object tree" in the interface{} was actually an int, and this was allowed by our data model but not by your library. Would that make sense?

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

No branches or pull requests

2 participants