Skip to content

Commit

Permalink
DefaultHttpCookiePair#parseCookiePair more strict overflow detection (#…
Browse files Browse the repository at this point in the history
…1292)

Motivation:
DefaultHttpCookiePair#parseCookiePair doesn't check for overflow when
calculating the value starting index.

Modifications:
- Check for overflow when calculating overflow index.

Result:
More robust overflow detection in DefaultHttpCookiePair#parseCookiePair.
  • Loading branch information
Scottmitch authored Dec 18, 2020
1 parent 7f80758 commit 127e145
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ public static HttpCookiePair parseCookiePair(final CharSequence sequence, int na
return parseCookiePair0(sequence, nameStart, nameLength, valueEnd < 0 ? sequence.length() : valueEnd);
}

static HttpCookiePair parseCookiePair0(final CharSequence sequence, int nameStart, int nameLength, int valueEnd) {
private static HttpCookiePair parseCookiePair0(final CharSequence sequence, int nameStart, int nameLength,
int valueEnd) {
final int valueStart = nameStart + nameLength + 1;
if (valueEnd - 1 < valueStart) {
throw new IllegalArgumentException("unexpected format of cookie pair, empty value");
if (valueEnd <= valueStart || valueStart < 0) {
throw new IllegalArgumentException("value indexes are invalid. valueStart: " + valueStart
+ " valueEnd: " + valueEnd);
}
if (sequence.charAt(valueStart) == '"' && sequence.charAt(valueEnd - 1) == '"') {
if (valueEnd - 2 <= valueStart) {
Expand Down

0 comments on commit 127e145

Please sign in to comment.