From eba3b8a335d864e8688bfeea12e329221688f35c Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 25 Mar 2008 23:36:56 +0000 Subject: [PATCH] Fix bug 44673. Throw IOE if stream is closed and a call is made to any read(), ready(), mark(), reset(), or skip() method as per javadocs for Reader. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@641076 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/catalina/connector/InputBuffer.java | 44 +++++++++++++++++++++- .../catalina/connector/LocalStrings.properties | 11 ++---- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/java/org/apache/catalina/connector/InputBuffer.java b/java/org/apache/catalina/connector/InputBuffer.java index ed762ca90..6bd484a38 100644 --- a/java/org/apache/catalina/connector/InputBuffer.java +++ b/java/org/apache/catalina/connector/InputBuffer.java @@ -25,6 +25,7 @@ import java.security.PrivilegedExceptionAction; import java.util.HashMap; import org.apache.catalina.security.SecurityUtil; +import org.apache.catalina.util.StringManager; import org.apache.coyote.ActionCode; import org.apache.coyote.Request; import org.apache.tomcat.util.buf.B2CConverter; @@ -44,6 +45,12 @@ public class InputBuffer extends Reader implements ByteChunk.ByteInputChannel, CharChunk.CharInputChannel, CharChunk.CharOutputChannel { + /** + * The string manager for this package. + */ + protected static StringManager sm = + StringManager.getManager(Constants.Package); + // -------------------------------------------------------------- Constants @@ -58,7 +65,6 @@ public class InputBuffer extends Reader public final int CHAR_STATE = 1; public final int BYTE_STATE = 2; - // ----------------------------------------------------- Instance Variables @@ -285,12 +291,20 @@ public class InputBuffer extends Reader public int readByte() throws IOException { + + if (closed) + throw new IOException(sm.getString("inputBuffer.streamClosed")); + return bb.substract(); } public int read(byte[] b, int off, int len) throws IOException { + + if (closed) + throw new IOException(sm.getString("inputBuffer.streamClosed")); + return bb.substract(b, off, len); } @@ -346,18 +360,30 @@ public class InputBuffer extends Reader public int read() throws IOException { + + if (closed) + throw new IOException(sm.getString("inputBuffer.streamClosed")); + return cb.substract(); } public int read(char[] cbuf) throws IOException { + + if (closed) + throw new IOException(sm.getString("inputBuffer.streamClosed")); + return read(cbuf, 0, cbuf.length); } public int read(char[] cbuf, int off, int len) throws IOException { + + if (closed) + throw new IOException(sm.getString("inputBuffer.streamClosed")); + return cb.substract(cbuf, off, len); } @@ -365,6 +391,10 @@ public class InputBuffer extends Reader public long skip(long n) throws IOException { + + if (closed) + throw new IOException(sm.getString("inputBuffer.streamClosed")); + if (n < 0) { throw new IllegalArgumentException(); } @@ -396,6 +426,10 @@ public class InputBuffer extends Reader public boolean ready() throws IOException { + + if (closed) + throw new IOException(sm.getString("inputBuffer.streamClosed")); + return (available() > 0); } @@ -407,6 +441,10 @@ public class InputBuffer extends Reader public void mark(int readAheadLimit) throws IOException { + + if (closed) + throw new IOException(sm.getString("inputBuffer.streamClosed")); + if (cb.getLength() <= 0) { cb.setOffset(0); cb.setEnd(0); @@ -430,6 +468,10 @@ public class InputBuffer extends Reader public void reset() throws IOException { + + if (closed) + throw new IOException(sm.getString("inputBuffer.streamClosed")); + if (state == CHAR_STATE) { if (markPos < 0) { cb.recycle(); diff --git a/java/org/apache/catalina/connector/LocalStrings.properties b/java/org/apache/catalina/connector/LocalStrings.properties index 68ada1b20..66e301a5a 100644 --- a/java/org/apache/catalina/connector/LocalStrings.properties +++ b/java/org/apache/catalina/connector/LocalStrings.properties @@ -17,7 +17,6 @@ # # CoyoteConnector # - coyoteConnector.alreadyInitialized=The connector has already been initialized coyoteConnector.alreadyStarted=The connector has already been started coyoteConnector.cannotRegisterProtocol=Cannot register MBean for the Protocol @@ -32,18 +31,15 @@ coyoteConnector.protocolHandlerResumeFailed=Protocol handler resume failed coyoteConnector.MapperRegistration=register Mapper: {0} coyoteConnector.protocolUnregistrationFailed=Protocol handler stop failed - # # CoyoteAdapter # - coyoteAdapter.service=An exception or error occurred in the container during the request processing coyoteAdapter.read=The servlet did not read all available bytes during the processing of the read event # # CoyoteResponse # - coyoteResponse.getOutputStream.ise=getWriter() has already been called for this response coyoteResponse.getWriter.ise=getOutputStream() has already been called for this response coyoteResponse.resetBuffer.ise=Cannot reset buffer after response has been committed @@ -54,7 +50,6 @@ coyoteResponse.setBufferSize.ise=Cannot change buffer size after data has been w # # CoyoteRequest # - coyoteRequest.getInputStream.ise=getReader() has already been called for this request coyoteRequest.getReader.ise=getInputStream() has already been called for this request coyoteRequest.sessionCreateCommitted=Cannot create a session after the response has been committed @@ -64,8 +59,11 @@ coyoteRequest.listenerStop=Exception sending context destroyed event to listener coyoteRequest.attributeEvent=Exception thrown by attributes event listener coyoteRequest.parseParameters=Exception thrown whilst processing POSTed parameters coyoteRequest.postTooLarge=Parameters were not parsed because the size of the posted data was too big. Use the maxPostSize attribute of the connector to resolve this if the application should accept large POSTs. + requestFacade.nullRequest=The request object has been recycled and is no longer associated with this facade + responseFacade.nullResponse=The response object has been recycled and is no longer associated with this facade + cometEvent.nullRequest=The event object has been recycled and is no longer associated with a request # @@ -78,5 +76,4 @@ mapperListener.registerContext=Register Context {0} mapperListener.unregisterContext=Unregister Context {0} mapperListener.registerWrapper=Register Wrapper {0} in Context {1} - - +inputBuffer.streamClosed=Stream closed \ No newline at end of file -- 2.11.0