olegk       2004/07/19 13:24:21

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        StatusLine.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestStatusLine.java
  Log:
  PR #30175 (StatusLine IndexOutOfBounds)
  
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.14      +31 -37    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/StatusLine.java
  
  Index: StatusLine.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/StatusLine.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- StatusLine.java   18 Apr 2004 23:51:35 -0000      1.13
  +++ StatusLine.java   19 Jul 2004 20:24:21 -0000      1.14
  @@ -92,47 +92,41 @@
                   throw new HttpException("Status-Line '" + statusLine 
                       + "' does not start with HTTP");
               }
  -        } catch (StringIndexOutOfBoundsException e) {
  -            throw new HttpException("Status-Line '" + statusLine + "' is not 
valid"); 
  -        }
  -        //handle the HTTP-Version
  -        at = statusLine.indexOf(" ", at);
  -        if (at <= 0) {
  -            throw new ProtocolException(
  -                    "Unable to parse HTTP-Version from the status line: '"
  -                    + statusLine + "'");
  -        }
  -        this.httpVersion = (statusLine.substring(start, at)).toUpperCase();
  -
  -        //advance through spaces
  -        while (statusLine.charAt(at) == ' ') {
  -            at++;
  -        }
  +            //handle the HTTP-Version
  +            at = statusLine.indexOf(" ", at);
  +            if (at <= 0) {
  +                throw new ProtocolException(
  +                        "Unable to parse HTTP-Version from the status line: '"
  +                        + statusLine + "'");
  +            }
  +            this.httpVersion = (statusLine.substring(start, at)).toUpperCase();
   
  -        //handle the Status-Code
  -        int to = statusLine.indexOf(" ", at);
  -        if (to < 0) {
  -            to = length;
  -        }
  -        try {
  -            this.statusCode = Integer.parseInt(statusLine.substring(at, to));
  -        } catch (NumberFormatException e) {
  -            throw new ProtocolException(
  -                "Unable to parse status code from status line: '" 
  -                + statusLine + "'");
  -        }
  +            //advance through spaces
  +            while (statusLine.charAt(at) == ' ') {
  +                at++;
  +            }
   
  -        //handle the Reason-Phrase
  -        at = to + 1;
  -        try {
  +            //handle the Status-Code
  +            int to = statusLine.indexOf(" ", at);
  +            if (to < 0) {
  +                to = length;
  +            }
  +            try {
  +                this.statusCode = Integer.parseInt(statusLine.substring(at, to));
  +            } catch (NumberFormatException e) {
  +                throw new ProtocolException(
  +                    "Unable to parse status code from status line: '" 
  +                    + statusLine + "'");
  +            }
  +            //handle the Reason-Phrase
  +            at = to + 1;
               if (at < length) {
                   this.reasonPhrase = statusLine.substring(at).trim();
               } else {
                   this.reasonPhrase = "";
               }
           } catch (StringIndexOutOfBoundsException e) {
  -            throw new ProtocolException("Status text not specified: '" 
  -                    + statusLine + "'");
  +            throw new HttpException("Status-Line '" + statusLine + "' is not 
valid"); 
           }
           //save the original Status-Line
           this.statusLine = new String(statusLine);
  
  
  
  1.9       +8 -4      
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestStatusLine.java
  
  Index: TestStatusLine.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestStatusLine.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestStatusLine.java       22 Feb 2004 18:08:49 -0000      1.8
  +++ TestStatusLine.java       19 Jul 2004 20:24:21 -0000      1.9
  @@ -139,6 +139,10 @@
               fail();
           } catch (HttpException e) { /* expected */ }
   
  +        try {
  +            statusLine = new StatusLine("HTTP/1.1    ");
  +            fail();
  +        } catch (HttpException e) { /* expected */ }
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to