From 0d7aef71bffcb4f28b3ebee65c9df365c7191f09 Mon Sep 17 00:00:00 2001 From: markt Date: Mon, 24 Mar 2008 20:52:42 +0000 Subject: [PATCH] Fix BZ 44620 https://issues.apache.org/bugzilla/show_bug.cgi?id=44620 Move the code that handles writing more than the output buffer can accept in a single write to the method that does the writing. This then protects all calls to addToBB() from the issue described in BZ 44620 and does not require the socket.appWriteBufSize to be >= maxHttpHeaderSize git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@640572 13f79535-47bb-0310-9956-ffa450edef68 --- .../coyote/http11/InternalNioOutputBuffer.java | 31 +++++++++++----------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/java/org/apache/coyote/http11/InternalNioOutputBuffer.java b/java/org/apache/coyote/http11/InternalNioOutputBuffer.java index 8539213bb..598c9a229 100644 --- a/java/org/apache/coyote/http11/InternalNioOutputBuffer.java +++ b/java/org/apache/coyote/http11/InternalNioOutputBuffer.java @@ -614,11 +614,21 @@ public class InternalNioOutputBuffer int total = 0; private synchronized void addToBB(byte[] buf, int offset, int length) throws IOException { - while (socket.getBufHandler().getWriteBuffer().remaining() < length) { - flushBuffer(); + while (length > 0) { + int thisTime = length; + if (socket.getBufHandler().getWriteBuffer().position() == + socket.getBufHandler().getWriteBuffer().capacity() + || socket.getBufHandler().getWriteBuffer().remaining()==0) { + flushBuffer(); + } + if (thisTime > socket.getBufHandler().getWriteBuffer().remaining()) { + thisTime = socket.getBufHandler().getWriteBuffer().remaining(); + } + socket.getBufHandler().getWriteBuffer().put(buf, offset, thisTime); + length = length - thisTime; + offset = offset + thisTime; + total += thisTime; } - socket.getBufHandler().getWriteBuffer().put(buf, offset, length); - total += length; NioEndpoint.KeyAttachment ka = (NioEndpoint.KeyAttachment)socket.getAttachment(false); if ( ka!= null ) ka.access();//prevent timeouts for just doing client writes } @@ -794,18 +804,7 @@ public class InternalNioOutputBuffer int len = chunk.getLength(); int start = chunk.getStart(); byte[] b = chunk.getBuffer(); - while (len > 0) { - int thisTime = len; - if (socket.getBufHandler().getWriteBuffer().position() == socket.getBufHandler().getWriteBuffer().capacity() ||socket.getBufHandler().getWriteBuffer().remaining()==0) { - flushBuffer(); - } - if (thisTime > socket.getBufHandler().getWriteBuffer().remaining()) { - thisTime = socket.getBufHandler().getWriteBuffer().remaining(); - } - addToBB(b,start,thisTime); - len = len - thisTime; - start = start + thisTime; - } + addToBB(b, start, len); return chunk.getLength(); } -- 2.11.0