From f5db1184694e6ce7d159355a7742d75a7b8c32c8 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 13 Mar 2015 18:17:00 -0700 Subject: [PATCH] Fix crashes when headers are invalid --- src/github/daneren2005/serverproxy/ServerProxy.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/github/daneren2005/serverproxy/ServerProxy.java b/src/github/daneren2005/serverproxy/ServerProxy.java index a6c353f..e505952 100644 --- a/src/github/daneren2005/serverproxy/ServerProxy.java +++ b/src/github/daneren2005/serverproxy/ServerProxy.java @@ -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(); @@ -177,7 +180,8 @@ 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); @@ -185,6 +189,8 @@ protected HttpRequest readRequest() { } } catch(IOException e) { // Don't really care once past first line + } catch(Exception e) { + Log.w(TAG, "Exception reading request", e); } return request;