Author: remy.maucherat(a)jboss.com
Date: 2014-06-12 07:27:01 -0400 (Thu, 12 Jun 2014)
New Revision: 2455
Modified:
branches/7.4.x/src/main/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
branches/7.4.x/src/main/java/org/jboss/web/CoyoteMessages.java
Log:
Port code cleanup from Tomcat for exception handling.
Modified:
branches/7.4.x/src/main/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
===================================================================
---
branches/7.4.x/src/main/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java 2014-06-11
08:37:57 UTC (rev 2454)
+++
branches/7.4.x/src/main/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java 2014-06-12
11:27:01 UTC (rev 2455)
@@ -103,6 +103,11 @@
*/
protected boolean needCRLFParse = false;
+ /**
+ * Flag that indicates if an error has occurred.
+ */
+ private boolean error;
+
// ------------------------------------------------------------- Properties
@@ -124,6 +129,8 @@
if (endChunk)
return -1;
+ checkError();
+
if (needCRLFParse) {
needCRLFParse = false;
// FIXME: parse CRLF could return 0 in NB
@@ -223,6 +230,7 @@
lastValid = 0;
endChunk = false;
needCRLFParse = false;
+ error = false;
}
@@ -278,6 +286,7 @@
// In non blocking mode, no new chunk follows, even if data was present
int n = readBytes();
if (n < 0) {
+ error = true;
throw MESSAGES.invalidChunkHeader();
} else if (n == 0) {
return false;
@@ -293,6 +302,7 @@
} else if (buf[pos] == Constants.SEMI_COLON) {
trailer = true;
} else if (buf[pos] < 0) {
+ error = true;
throw MESSAGES.invalidChunkHeader();
} else if (!trailer) {
//don't read data after the trailer
@@ -303,6 +313,7 @@
} else {
//we shouldn't allow invalid, non hex characters
//in the chunked header
+ error = true;
throw MESSAGES.invalidChunkHeader();
}
}
@@ -311,8 +322,10 @@
}
- if (readDigit == 0 || (result < 0))
+ if (readDigit == 0 || (result < 0)) {
+ error = true;
throw MESSAGES.invalidChunkHeader();
+ }
if (result == 0)
endChunk = true;
@@ -336,17 +349,26 @@
while (!eol) {
if (pos >= lastValid) {
- if (readBytes() <= 0)
+ if (readBytes() <= 0) {
+ error = true;
throw MESSAGES.invalidCrlf();
+ }
}
if (buf[pos] == Constants.CR) {
- if (crfound) throw MESSAGES.invalidCrlfTwoCr();
+ if (crfound) {
+ error = true;
+ throw MESSAGES.invalidCrlfTwoCr();
+ }
crfound = true;
} else if (buf[pos] == Constants.LF) {
- if (!crfound) throw MESSAGES.invalidCrlfNoCr();
+ if (!crfound) {
+ error = true;
+ throw MESSAGES.invalidCrlfNoCr();
+ }
eol = true;
} else {
+ error = true;
throw MESSAGES.invalidCrlf();
}
@@ -371,4 +393,10 @@
}
+ private void checkError() throws IOException {
+ if (error) {
+ throw new IOException(MESSAGES.chunkedFilterError());
+ }
+ }
+
}
Modified: branches/7.4.x/src/main/java/org/jboss/web/CoyoteMessages.java
===================================================================
--- branches/7.4.x/src/main/java/org/jboss/web/CoyoteMessages.java 2014-06-11 08:37:57 UTC
(rev 2454)
+++ branches/7.4.x/src/main/java/org/jboss/web/CoyoteMessages.java 2014-06-12 11:27:01 UTC
(rev 2455)
@@ -283,4 +283,7 @@
@Message(id = 2081, value = "No cipher match")
String noCipherMatch();
+ @Message(id = 2082, value = "Chunked input filter error")
+ String chunkedFilterError();
+
}
Show replies by date