From 7034a00093c07e2eae8d2233a981516907795b1f Mon Sep 17 00:00:00 2001 From: Wynne Crisman Date: Mon, 22 Feb 2016 10:30:17 -0800 Subject: [PATCH] Revert "Modified build script to use jdk 1.7 instead of 1.5 for building the release compile; Added debug output to try to identify the error where interestOps isn't set properly for a socket that isn't yet closed; Fixed index exception in identifying the host." This reverts commit 5d9ea7528bbda8833946fde46afe952694d5b8f3. --- Foundation Builder/builder/build.xml | 3 +- .../web/server/NetworkListener.java | 2 +- .../foundation/web/server/SocketContext.java | 54 ++++++++----------- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/Foundation Builder/builder/build.xml b/Foundation Builder/builder/build.xml index cea4f91..b1cdcea 100644 --- a/Foundation Builder/builder/build.xml +++ b/Foundation Builder/builder/build.xml @@ -113,8 +113,7 @@ - - + diff --git a/Foundation Web Core/src/com/foundation/web/server/NetworkListener.java b/Foundation Web Core/src/com/foundation/web/server/NetworkListener.java index 3e3d3d4..bebf097 100644 --- a/Foundation Web Core/src/com/foundation/web/server/NetworkListener.java +++ b/Foundation Web Core/src/com/foundation/web/server/NetworkListener.java @@ -238,7 +238,7 @@ public void run() { }//else if// else { //This shouldn't be called I don't think.// - Debug.log(new RuntimeException("Woops! Somehow we aren't closed and we didn't setup the interestOps for the HTTP socket! {" + context.toString() + "}")); + Debug.log(new RuntimeException("Woops! Somehow we aren't closed and we didn't setup the interestOps for the HTTP socket!")); }//else// }//finally// }//run()// diff --git a/Foundation Web Core/src/com/foundation/web/server/SocketContext.java b/Foundation Web Core/src/com/foundation/web/server/SocketContext.java index b7f6b7f..dd846a5 100644 --- a/Foundation Web Core/src/com/foundation/web/server/SocketContext.java +++ b/Foundation Web Core/src/com/foundation/web/server/SocketContext.java @@ -1259,36 +1259,32 @@ private boolean processRequestedHost(ByteBuffer fragment) throws IOException { totalHeaderSize++; }//while// - //If we have a full line... - if(buffer.length() > 1 && (buffer.charAt(buffer.length() - 2) == '\r') && (buffer.charAt(buffer.length() - 1) == '\n')) { - //If we have the minimum number of bytes and the last bytes are a line end, then check the line for "Host: xxxxxxx\r\n" - String line = buffer.toString().substring(0, buffer.length() - 2).trim(); + //If we have the minimum number of bytes and the last bytes are a line end, then check the line for "Host: xxxxxxx\r\n" + String line = buffer.toString().substring(0, buffer.length() - 2).trim(); + if(line.startsWith("Host: ")) { + int colonIndex; - if(line.startsWith("Host: ")) { - int colonIndex; - - host = line.substring(6).trim(); - colonIndex = host.indexOf(':'); - - if(colonIndex > 0) { - host = host.substring(0, colonIndex); - }//if// - }//if// + host = line.substring(6).trim(); + colonIndex = host.indexOf(':'); - if(host == null) { - if(buffer.length() == 2) { - //End of the header reached. No host provided. Kill the connection?// - //Force the connection to the client to be closed.// - close(); - //Throw an exception that should not be logged. This happens occationally when an attacker tries to exploit any header reading weaknesses (all major browsers send a host header).// - throw new IgnoredIOException(null); - }//if// - else { - //Clear the line.// - buffer.setLength(0); - }//else// + if(colonIndex > 0) { + host = host.substring(0, colonIndex); }//if// }//if// + + if(host == null) { + if(buffer.length() == 2) { + //End of the header reached. No host provided. Kill the connection?// + //Force the connection to the client to be closed.// + close(); + //Throw an exception that should not be logged. This happens occationally when an attacker tries to exploit any header reading weaknesses (all major browsers send a host header).// + throw new IgnoredIOException(null); + }//if// + else { + //Clear the line.// + buffer.setLength(0); + }//else// + }//if// }//while// //If we found the complete first line of the header before running out of bytes, then identify the application.// @@ -2241,10 +2237,4 @@ private int indexOf(byte[] source, byte[] pattern, int fromOffset) { return result; }//indexOf()// -/* (non-Javadoc) - * @see java.lang.Object#toString() - */ -public String toString() { - return "Domain: " + domain + "; SSL: " + (sslEngine != null) + "; Websocket: " + isWebsocket; -}//toString()// }//SocketContext// \ No newline at end of file