This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 198d63b2ad2ce564c06fb597304d85ab9e350a8c Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Aug 21 16:34:10 2020 +0100 Avoid possible NPE when stream is closed --- java/org/apache/coyote/http2/Stream.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/java/org/apache/coyote/http2/Stream.java b/java/org/apache/coyote/http2/Stream.java index 2530982..1b750ef 100644 --- a/java/org/apache/coyote/http2/Stream.java +++ b/java/org/apache/coyote/http2/Stream.java @@ -594,10 +594,10 @@ public class Stream extends AbstractStream implements HeaderEmitter { final void receivedEndOfStream() throws ConnectionException { - long contentLengthHeader = coyoteRequest.getContentLengthLong(); - if (contentLengthHeader > -1 && contentLengthReceived != contentLengthHeader) { + if (isContentLengthInconsistent()) { throw new ConnectionException(sm.getString("stream.header.contentLength", - getConnectionId(), getIdentifier(), Long.valueOf(contentLengthHeader), + getConnectionId(), getIdentifier(), + Long.valueOf(coyoteRequest.getContentLengthLong()), Long.valueOf(contentLengthReceived)), Http2Error.PROTOCOL_ERROR); } state.receivedEndOfStream(); @@ -607,6 +607,20 @@ public class Stream extends AbstractStream implements HeaderEmitter { } + final boolean isContentLengthInconsistent() { + Request coyoteRequest = this.coyoteRequest; + // May be null when processing trailer headers after stream has been + // closed. + if (coyoteRequest != null) { + long contentLengthHeader = coyoteRequest.getContentLengthLong(); + if (contentLengthHeader > -1 && contentLengthReceived != contentLengthHeader) { + return true; + } + } + return false; + } + + final void sentHeaders() { state.sentStartOfHeaders(); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org