olegk       2004/07/19 13:25:02

  Modified:    httpclient/src/java/org/apache/commons/httpclient Tag:
                        HTTPCLIENT_2_0_BRANCH StatusLine.java
               httpclient/src/test/org/apache/commons/httpclient Tag:
                        HTTPCLIENT_2_0_BRANCH TestStatusLine.java
  Log:
  PR #30175 (StatusLine IndexOutOfBounds)
  
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.9.2.4   +30 -38    
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.9.2.3
  retrieving revision 1.9.2.4
  diff -u -r1.9.2.3 -r1.9.2.4
  --- StatusLine.java   22 Feb 2004 18:21:13 -0000      1.9.2.3
  +++ StatusLine.java   19 Jul 2004 20:25:02 -0000      1.9.2.4
  @@ -96,47 +96,39 @@
                   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 HttpException(
  -                    "Unable to parse HTTP-Version from the status line: '"
  +            //handle the HTTP-Version
  +            at = statusLine.indexOf(" ", at);
  +            if (at <= 0) {
  +                throw new HttpException(
  +                        "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 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 HttpException(
  +                    "Unable to parse status code from status line: '" 
                       + statusLine + "'");
  -        }
  -        this.httpVersion = (statusLine.substring(start, at)).toUpperCase();
  -
  -        //advance through spaces
  -        while (statusLine.charAt(at) == ' ') {
  -            at++;
  -        }
  -
  -        //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 HttpException(
  -                "Unable to parse status code from status line: '" 
  -                + statusLine + "'");
  -        }
  -
  -        //handle the Reason-Phrase
  -        at = to + 1;
  -        try {
  +            }
  +            //handle the Reason-Phrase
  +            at = to + 1;
               if (at < length) {
                   this.reasonPhrase = statusLine.substring(at).trim();
               } else {
                   this.reasonPhrase = "";
               }
           } catch (StringIndexOutOfBoundsException e) {
  -            throw new HttpException("Status text not specified: '" 
  -                    + statusLine + "'");
  +            throw new HttpException("Status-Line '" + statusLine + "' is not 
valid"); 
           }
           //save the original Status-Line if everything is OK
           this.statusLine = new String(statusLine);
  
  
  
  No                   revision
  No                   revision
  1.6.2.3   +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.6.2.2
  retrieving revision 1.6.2.3
  diff -u -r1.6.2.2 -r1.6.2.3
  --- TestStatusLine.java       22 Feb 2004 18:21:16 -0000      1.6.2.2
  +++ TestStatusLine.java       19 Jul 2004 20:25:02 -0000      1.6.2.3
  @@ -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