tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billbar...@apache.org
Subject svn commit: r586870 - /tomcat/connectors/trunk/jk/java/org/apache/jk/common/ChannelNioSocket.java
Date Sun, 21 Oct 2007 08:31:16 GMT
Author: billbarker
Date: Sun Oct 21 01:31:12 2007
New Revision: 586870

URL: http://svn.apache.org/viewvc?rev=586870&view=rev
Log:
Fix possible DoS condition for the experimental NIO/AJP module 

Fix for bug #43621

Reported By: William Leung

Modified:
    tomcat/connectors/trunk/jk/java/org/apache/jk/common/ChannelNioSocket.java

Modified: tomcat/connectors/trunk/jk/java/org/apache/jk/common/ChannelNioSocket.java
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/java/org/apache/jk/common/ChannelNioSocket.java?rev=586870&r1=586869&r2=586870&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/java/org/apache/jk/common/ChannelNioSocket.java (original)
+++ tomcat/connectors/trunk/jk/java/org/apache/jk/common/ChannelNioSocket.java Sun Oct 21
01:31:12 2007
@@ -36,6 +36,7 @@
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.SocketException;
+import java.net.SocketTimeoutException;
 
 import javax.management.ListenerNotFoundException;
 import javax.management.MBeanNotificationInfo;
@@ -882,6 +883,8 @@
 
         synchronized void  process(SelectionKey sk) {
             if(!sk.isValid()) {
+                SocketInputStream sis = (SocketInputStream)ep.getNote(isNote);
+                sis.closeIt();
                 return;
             }
             if(sk.isReadable()) {
@@ -959,15 +962,11 @@
                         Iterator it = sels.iterator();
                         while(it.hasNext()) {
                             SelectionKey sk = (SelectionKey)it.next();
-                            if(sk.isValid()) {
-                                if(sk.isAcceptable()) {
-                                    acceptConnections();
-                                } else {
-                                    SocketConnection sc = (SocketConnection)sk.attachment();
-                                    sc.process(sk);
-                                }
+                            if(sk.isAcceptable()) {
+                                acceptConnections();
                             } else {
-                                sk.cancel();
+                                SocketConnection sc = (SocketConnection)sk.attachment();
+                                sc.process(sk);
                             }
                             it.remove();
                         }
@@ -1081,8 +1080,7 @@
                     nr = -1; // Can't handle this yet
                 }
                 if(nr < 0) {
-                    isClosed = true;
-                    notify();
+                    closeIt();
                     return false;
                 } else if(nr == 0) {
                     if(!nioIsBroken) {
@@ -1093,6 +1091,12 @@
             return true;
         }
 
+        synchronized void closeIt() {
+            isClosed = true;
+            if(blocking)
+                notify();
+        }
+
         public int read(byte [] data) throws IOException {
             return read(data, 0, data.length);
         }
@@ -1132,7 +1136,9 @@
                 if(fill(len) < 0) {
                     isClosed = true;
                 } 
-            }
+            } else if(!isClosed) {
+		throw new SocketTimeoutException("Read request timed out");
+	    }
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message