Skip to content

Commit

Permalink
Fix crashes when headers are invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
daneren2005 committed Mar 14, 2015
1 parent 6976d20 commit f5db118
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/github/daneren2005/serverproxy/ServerProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ protected HttpRequest readRequest() {

StringTokenizer st = new StringTokenizer(firstLine);
if(!st.hasMoreTokens()) {
Log.w(TAG, "Unknown error with no tokens");
Log.w(TAG, "Unknown request with no tokens");
return request;
} else if(st.countTokens() < 2) {
Log.w(TAG, "Unknown request with no uri: \"" + firstLine + '"');
return request;
}
String method = st.nextToken();
Expand All @@ -177,14 +180,17 @@ protected HttpRequest readRequest() {
String line;
while((line = reader.readLine()) != null && !"".equals(line)) {
int index = line.indexOf(':');
if(index != -1) {
// Ignore headers without ':' or where ':' is the last thing in the string
if(index != -1 && (index + 2) < line.length()) {
String headerName = line.substring(0, index);
String headerValue = line.substring(index + 2);
request.addHeader(headerName, headerValue);
}
}
} catch(IOException e) {
// Don't really care once past first line
} catch(Exception e) {
Log.w(TAG, "Exception reading request", e);
}

return request;
Expand Down

0 comments on commit f5db118

Please sign in to comment.