Author: kkolinko
Date: Tue Jun 5 12:13:07 2012
New Revision: 1346365
URL: http://svn.apache.org/viewvc?rev=1346365&view=rev
Log:
For https://issues.apache.org/bugzilla/show_bug.cgi?id=53119
Port r1344253 to AjpNioProcessor
Prevent possible overflow exception with buffer in AjpNioProcessor.output() if
it is called again after the previous write failed with IOException.
This is based on review of the issue fixed by r1344253. I see several reasons
why it is hard to observe in Nio, but it is easy to prevent this issue. An
overflow exception is bad because it is RuntimeException and is generally
unexpected. This change:
- avoids writing to the buffer if att == null
- always clears the buffer. Note that Buffer.clear() method is rather
lightweight one.
Modified:
tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java?rev=1346365&r1=1346364&r2=1346365&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java Tue Jun 5
12:13:07 2012
@@ -276,14 +276,16 @@ public class AjpNioProcessor extends Abs
@Override
protected void output(byte[] src, int offset, int length)
throws IOException {
+
+ NioEndpoint.KeyAttachment att =
(NioEndpoint.KeyAttachment)socket.getAttachment(false);
+ if ( att == null ) throw new IOException("Key must be cancelled");
+
ByteBuffer writeBuffer = socket.getBufHandler() .getWriteBuffer();
writeBuffer.put(src, offset, length);
writeBuffer.flip();
- NioEndpoint.KeyAttachment att =
(NioEndpoint.KeyAttachment)socket.getAttachment(false);
- if ( att == null ) throw new IOException("Key must be cancelled");
long writeTimeout = att.getTimeout();
Selector selector = null;
try {
@@ -294,9 +296,9 @@ public class AjpNioProcessor extends Abs
try {
pool.write(writeBuffer, socket, selector, writeTimeout, true);
}finally {
+ writeBuffer.clear();
if ( selector != null ) pool.put(selector);
}
- writeBuffer.clear();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]