Skip to content

Commit

Permalink
Fix edge case panic in ParseID (#1249)
Browse files Browse the repository at this point in the history
  • Loading branch information
bayandin authored Feb 17, 2021
1 parent 9061e06 commit 417a16e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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 == "\"" {
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

0 comments on commit 417a16e

Please sign in to comment.