Uploaded image for project: 'JBoss Web Server'
  1. JBoss Web Server
  2. JWS-824

Negative maxCookieCount value causes exception

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • JWS 5.0_RHEL DR1
    • JWS 3.1.0 SP1 CR2, JWS 4.0.0 DR2
    • tomcat
    • None
    • Hide
      • In CATALINA_HOME/conf/server.xml, set max cookie count for your connector:
      <Connector port="8080" protocol="HTTP/1.1"
                     connectionTimeout="20000"
                     redirectPort="8443"
                     maxCookieCount="-1"
                      />
      
      • Start tomcat
      • Send a request with cookies, for example:
      import java.net.HttpURLConnection;
      import java.net.URL;
      
      public class Main {
          private final String USER_AGENT = "Mozilla/5.0";
          private final String URL = "http://192.168.122.201:8080";
      
          public static void main(String[] args) throws Exception {
              Main http = new Main();
              System.out.println("Testing - send http GET request with cookies");
              http.sendGet();
          }
      
          private void sendGet() throws Exception {
              URL obj = new URL(URL);
              HttpURLConnection con = (HttpURLConnection) obj.openConnection();
      
              // optional default is GET
              con.setRequestMethod("GET");
      
              // add request header
              con.setRequestProperty("User-Agent", USER_AGENT);
      
              StringBuilder sb = new StringBuilder();
      
              // add #i-1 cookies, separated by ;
              for(int i = 0;i<10;i++){
                  sb.append("a=b;");
      
              }
      
              // set the cookie header
              con.setRequestProperty("Cookie",sb.toString());
      
              int responseCode = con.getResponseCode();
              System.out.println("\nSending 'GET' request to URL : " + URL);
              System.out.println("Response Code : " + responseCode);
          }
      }
      
      

      Expected result: 200
      Actual result: 500

      Show
      In CATALINA_HOME/conf/server.xml, set max cookie count for your connector: <Connector port= "8080" protocol= "HTTP/1.1" connectionTimeout= "20000" redirectPort= "8443" maxCookieCount= "-1" /> Start tomcat Send a request with cookies, for example: import java.net.HttpURLConnection; import java.net.URL; public class Main { private final String USER_AGENT = "Mozilla/5.0" ; private final String URL = "http: //192.168.122.201:8080" ; public static void main( String [] args) throws Exception { Main http = new Main(); System .out.println( "Testing - send http GET request with cookies" ); http.sendGet(); } private void sendGet() throws Exception { URL obj = new URL(URL); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); // optional default is GET con.setRequestMethod( "GET" ); // add request header con.setRequestProperty( "User-Agent" , USER_AGENT); StringBuilder sb = new StringBuilder(); // add #i-1 cookies, separated by ; for ( int i = 0;i<10;i++){ sb.append( "a=b;" ); } // set the cookie header con.setRequestProperty( "Cookie" ,sb.toString()); int responseCode = con.getResponseCode(); System .out.println( "\nSending 'GET' request to URL : " + URL); System .out.println( "Response Code : " + responseCode); } } Expected result: 200 Actual result: 500

      When reading the Tomcat Documentation, the maxCookieCount says: "... A value of less than zero means no limit. ..." However, when setting the value to -1 in server.xml and send a request with cookies, I get the following error:

          19-Sep-2017 13:21:14.318 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 766 ms
          19-Sep-2017 13:21:46.590 SEVERE [http-nio-8080-exec-1] org.apache.coyote.http11.Http11Processor.service Error processing request
           java.lang.NegativeArraySizeException
                  at org.apache.tomcat.util.http.ServerCookies.addCookie(ServerCookies.java:53)
                  at org.apache.tomcat.util.http.parser.Cookie.parseCookieRfc6265(Cookie.java:235)
                  at org.apache.tomcat.util.http.parser.Cookie.parseCookie(Cookie.java:122)
                  at org.apache.tomcat.util.http.Rfc6265CookieProcessor.parseCookieHeader(Rfc6265CookieProcessor.java:90)
                  at org.apache.catalina.connector.Request.parseCookies(Request.java:3099)
                  at org.apache.catalina.connector.Request.getServerCookies(Request.java:2169)
                  at org.apache.catalina.connector.CoyoteAdapter.parseSessionCookiesId(CoyoteAdapter.java:1007)
                  at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:714)
                  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336)
                  at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
                  at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
                  at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
                  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
                  at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
                  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
                  at java.lang.Thread.run(Thread.java:748)
      
      

      This happens on:

      • JWS 3.1, Tomcat 7 and 8
      • JWS 4 DR2

      This is likely caused in ServerCookies.java, the following line of code:

      ServerCookie scookiesTmp[] = new ServerCookie[newSize];
      

              rhn-support-csutherl Coty Sutherland
              mczernek@redhat.com Marek Czernek (Inactive)
              Marek Czernek Marek Czernek (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: