Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 17F1791F0 for ; Tue, 5 Jun 2012 12:13:33 +0000 (UTC) Received: (qmail 78810 invoked by uid 500); 5 Jun 2012 12:13:32 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 78589 invoked by uid 500); 5 Jun 2012 12:13:31 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 78563 invoked by uid 99); 5 Jun 2012 12:13:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jun 2012 12:13:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jun 2012 12:13:28 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 088B023888CD for ; Tue, 5 Jun 2012 12:13:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1346365 - /tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java Date: Tue, 05 Jun 2012 12:13:07 -0000 To: dev@tomcat.apache.org From: kkolinko@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120605121308.088B023888CD@eris.apache.org> 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: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org