Description: fix denial of service and possible information disclosure
 via crafted header
Origin: upstream, http://svn.apache.org/viewvc?view=revision&revision=958977
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=588813

Index: tomcat6-6.0.24/java/org/apache/coyote/http11/Http11AprProcessor.java
===================================================================
--- tomcat6-6.0.24.orig/java/org/apache/coyote/http11/Http11AprProcessor.java	2010-08-19 10:06:13.000000000 -0400
+++ tomcat6-6.0.24/java/org/apache/coyote/http11/Http11AprProcessor.java	2010-08-19 10:06:50.000000000 -0400
@@ -78,6 +78,12 @@
     protected static StringManager sm =
         StringManager.getManager(Constants.Package);
 
+    /*
+     * Tracks how many internal filters are in the filter library so they
+     * are skipped when looking for pluggable filters. 
+     */
+    private int pluggableFilterIndex = Integer.MAX_VALUE;
+
 
     // ----------------------------------------------------------- Constructors
 
@@ -1736,6 +1742,8 @@
         //inputBuffer.addFilter(new GzipInputFilter());
         outputBuffer.addFilter(new GzipOutputFilter());
 
+        pluggableFilterIndex = inputBuffer.filterLibrary.length;
+
     }
 
 
@@ -1754,7 +1762,7 @@
                 (inputFilters[Constants.CHUNKED_FILTER]);
             contentDelimitation = true;
         } else {
-            for (int i = 2; i < inputFilters.length; i++) {
+            for (int i = pluggableFilterIndex; i < inputFilters.length; i++) {
                 if (inputFilters[i].getEncodingName()
                     .toString().equals(encodingName)) {
                     inputBuffer.addActiveFilter(inputFilters[i]);
Index: tomcat6-6.0.24/java/org/apache/coyote/http11/Http11NioProcessor.java
===================================================================
--- tomcat6-6.0.24.orig/java/org/apache/coyote/http11/Http11NioProcessor.java	2010-08-19 10:06:23.000000000 -0400
+++ tomcat6-6.0.24/java/org/apache/coyote/http11/Http11NioProcessor.java	2010-08-19 10:06:53.000000000 -0400
@@ -81,6 +81,13 @@
      */
     protected SSLSupport sslSupport;
 
+    /*
+     * Tracks how many internal filters are in the filter library so they
+     * are skipped when looking for pluggable filters. 
+     */
+    private int pluggableFilterIndex = Integer.MAX_VALUE;
+
+
     // ----------------------------------------------------------- Constructors
 
 
@@ -1763,6 +1770,8 @@
         //inputBuffer.addFilter(new GzipInputFilter());
         outputBuffer.addFilter(new GzipOutputFilter());
 
+        pluggableFilterIndex = inputBuffer.filterLibrary.length;
+
     }
 
 
@@ -1781,7 +1790,7 @@
                 (inputFilters[Constants.CHUNKED_FILTER]);
             contentDelimitation = true;
         } else {
-            for (int i = 2; i < inputFilters.length; i++) {
+            for (int i = pluggableFilterIndex; i < inputFilters.length; i++) {
                 if (inputFilters[i].getEncodingName()
                     .toString().equals(encodingName)) {
                     inputBuffer.addActiveFilter(inputFilters[i]);
Index: tomcat6-6.0.24/java/org/apache/coyote/http11/Http11Processor.java
===================================================================
--- tomcat6-6.0.24.orig/java/org/apache/coyote/http11/Http11Processor.java	2010-08-19 10:06:30.000000000 -0400
+++ tomcat6-6.0.24/java/org/apache/coyote/http11/Http11Processor.java	2010-08-19 10:06:55.000000000 -0400
@@ -76,6 +76,13 @@
     protected static boolean isSecurityEnabled = 
 	org.apache.coyote.Constants.IS_SECURITY_ENABLED;
 
+    /*
+     * Tracks how many internal filters are in the filter library so they
+     * are skipped when looking for pluggable filters. 
+     */
+    private int pluggableFilterIndex = Integer.MAX_VALUE;
+
+
     // ------------------------------------------------------------ Constructor
 
 
@@ -1642,6 +1649,8 @@
         //inputBuffer.addFilter(new GzipInputFilter());
         outputBuffer.addFilter(new GzipOutputFilter());
 
+        pluggableFilterIndex = inputBuffer.filterLibrary.length;
+
     }
 
 
@@ -1660,7 +1669,7 @@
                 (inputFilters[Constants.CHUNKED_FILTER]);
             contentDelimitation = true;
         } else {
-            for (int i = 2; i < inputFilters.length; i++) {
+            for (int i = pluggableFilterIndex; i < inputFilters.length; i++) {
                 if (inputFilters[i].getEncodingName()
                     .toString().equals(encodingName)) {
                     inputBuffer.addActiveFilter(inputFilters[i]);
Index: tomcat6-6.0.24/java/org/apache/coyote/http11/filters/BufferedInputFilter.java
===================================================================
--- tomcat6-6.0.24.orig/java/org/apache/coyote/http11/filters/BufferedInputFilter.java	2010-08-19 10:06:38.000000000 -0400
+++ tomcat6-6.0.24/java/org/apache/coyote/http11/filters/BufferedInputFilter.java	2010-08-19 10:06:57.000000000 -0400
@@ -102,10 +102,12 @@
     }
 
     public void recycle() {
-        if (buffered.getBuffer().length > 65536) {
-            buffered = null;
-        } else {
-            buffered.recycle();
+        if (buffered != null) {
+            if (buffered.getBuffer().length > 65536) {
+                buffered = null;
+            } else {
+                buffered.recycle();
+            }
         }
         tempRead.recycle();
         hasRead = false;
