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 edge case panic in ParseID #1249

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,11 @@ func ParseID(data []byte) (string, bool) {
return "", false
}

// Edge case that should never happen; found via fuzzing
if s == "\"" {
bayandin marked this conversation as resolved.
Show resolved Hide resolved
return "", false
}

return s[1 : len(s)-1], true
}

Expand Down
7 changes: 7 additions & 0 deletions stripe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,13 @@ func TestParseID(t *testing.T) {
assert.Equal(t, "", id)
assert.False(t, ok)
}

// Edge case that should never happen; found via fuzzing
{
id, ok := ParseID([]byte(`"`))
assert.Equal(t, "", id)
assert.False(t, ok)
}
}

// TestMultipleAPICalls will fail the test run if a race condition is thrown while running multiple NewRequest calls.
Expand Down