From 954db729db7516ab487e7032fb769ea07c467013 Mon Sep 17 00:00:00 2001 From: theli Date: Thu, 30 Nov 2006 06:38:53 +0000 Subject: [PATCH] *) Bugfix for ArrayIndexOutOfBoundsException during SSL detection See: http://www.yacy-forum.de/viewtopic.php?p=28247#28247 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3025 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/server/serverCoreSocket.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/de/anomic/server/serverCoreSocket.java b/source/de/anomic/server/serverCoreSocket.java index 823953196..33c9dabdb 100644 --- a/source/de/anomic/server/serverCoreSocket.java +++ b/source/de/anomic/server/serverCoreSocket.java @@ -77,9 +77,17 @@ public class serverCoreSocket extends Socket { private void detectSSL() throws IOException { InputStream in = getInputStream(); - // read the first 6 bytes to determine the protocol type + // read the first 5 bytes to determine the protocol type byte[] preRead = new byte[5]; - int read = in.read(preRead); + int read, count = 0; + while ((count < preRead.length) && ((read = in.read()) != -1)) { + preRead[count] = (byte) read; + count++; + } + if (count < preRead.length) { + ((PushbackInputStream) in).unread(preRead,0,count); + return; + } int idx = 0; if ((preRead[0] & 0xFF) == 22) { @@ -114,7 +122,7 @@ public class serverCoreSocket extends Socket { } // unread pre read bytes - ((PushbackInputStream) in).unread(preRead,0,read); + ((PushbackInputStream) in).unread(preRead); } public InetAddress getInetAddress() {