olegk 2004/05/02 04:19:58
Modified: httpclient/src/java/org/apache/commons/httpclient Tag:
HTTPCLIENT_2_0_BRANCH HttpStatus.java
httpclient/src/test/org/apache/commons/httpclient Tag:
HTTPCLIENT_2_0_BRANCH TestHttpStatus.java
Log:
PR #28626 (ArrayIndexOutOfBoundsException in HttpStatus.getStatusText(508))
Contributed by Oleg Kalnichevski
Reviewed by Michael Becke
Revision Changes Path
No revision
No revision
1.15.2.2 +8 -5
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java
Index: HttpStatus.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java,v
retrieving revision 1.15.2.1
retrieving revision 1.15.2.2
diff -u -r1.15.2.1 -r1.15.2.2
--- HttpStatus.java 22 Feb 2004 18:21:13 -0000 1.15.2.1
+++ HttpStatus.java 2 May 2004 11:19:58 -0000 1.15.2.2
@@ -77,10 +77,13 @@
*/
public static String getStatusText(int statusCode) {
+ if (statusCode < 0) {
+ throw new IllegalArgumentException("status code may not be negative");
+ }
int classIndex = statusCode / 100;
int codeIndex = statusCode - classIndex * 100;
if (classIndex < 1 || classIndex > (REASON_PHRASES.length - 1)
- || codeIndex < 0 || codeIndex > REASON_PHRASES[classIndex].length) {
+ || codeIndex < 0 || codeIndex > (REASON_PHRASES[classIndex].length -
1)) {
return null;
}
return REASON_PHRASES[classIndex][codeIndex];
No revision
No revision
1.2.2.2 +17 -4
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpStatus.java
Index: TestHttpStatus.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpStatus.java,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -r1.2.2.1 -r1.2.2.2
--- TestHttpStatus.java 22 Feb 2004 18:21:16 -0000 1.2.2.1
+++ TestHttpStatus.java 2 May 2004 11:19:58 -0000 1.2.2.2
@@ -92,4 +92,17 @@
}
+ public void testStatusTextNegative() throws Exception {
+ try {
+ HttpStatus.getStatusText(-1);
+ fail("IllegalArgumentException must have been thrown");
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+ public void testStatusTextAll() throws Exception {
+ for (int i = 0; i < 600; i++) {
+ HttpStatus.getStatusText(i);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]