Michael's review - make sure the status line parsing considers only the space character

This commit is contained in:
Jaikiran Pai 2026-04-02 11:51:06 +05:30
parent a216241058
commit 3dbc2eb83c
2 changed files with 10 additions and 3 deletions

View File

@ -2041,7 +2041,11 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
if (statusLine == null || statusLine.isBlank()) {
return invalidStatusLine;
}
final StringTokenizer st = new StringTokenizer(statusLine);
//
// status-line = HTTP-version SP status-code SP [ reason-phrase ]
// SP = space character
//
final StringTokenizer st = new StringTokenizer(statusLine, " ");
if (!st.hasMoreTokens()) {
return invalidStatusLine;
}
@ -2049,7 +2053,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
if (!st.hasMoreTokens()) {
return invalidStatusLine;
}
final String v = st.nextToken().trim(); // response code
final String v = st.nextToken().trim(); // status code
try {
return Integer.parseInt(v);
} catch (NumberFormatException nfe) {

View File

@ -66,7 +66,10 @@ class ProxyBadStatusLine {
Arguments.of("HTTP/1.1\n", "Unable to tunnel through proxy"),
Arguments.of("HTTP/1.1 301 ", "Unable to tunnel through proxy"),
Arguments.of("HTTP/1.1 404 ", "Unable to tunnel through proxy"),
Arguments.of("HTTP/1.1 503 ", "Unable to tunnel through proxy")
Arguments.of("HTTP/1.1 503 ", "Unable to tunnel through proxy"),
Arguments.of("HTTP/1.1\n200 ", "Unable to tunnel through proxy"),
Arguments.of("HTTP/1.1\r200 ", "Unable to tunnel through proxy"),
Arguments.of("HTTP/1.1\f200 ", "Unable to tunnel through proxy")
);
}