This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 583b7ad Avoid potential NPEs introduced in smaller footprint for
closed streams
583b7ad is described below
commit 583b7ad17ff7cd67ac15a50e76cf2e0c5cd9138a
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Aug 12 18:12:43 2020 +0100
Avoid potential NPEs introduced in smaller footprint for closed streams
---
java/org/apache/coyote/http2/Stream.java | 18 ++++++++++++++++--
webapps/docs/changelog.xml | 4 ++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/java/org/apache/coyote/http2/Stream.java
b/java/org/apache/coyote/http2/Stream.java
index 396a24e..8b0a501 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -472,8 +472,12 @@ class Stream extends AbstractStream implements
HeaderEmitter {
}
if (headerState == HEADER_STATE_TRAILER) {
- // HTTP/2 headers are already always lower case
- coyoteRequest.getTrailerFields().put(name, value);
+ // Avoid NPE if Stream has been closed on Stream specific
thread
+ Request coyoteRequest = this.coyoteRequest;
+ if (coyoteRequest != null) {
+ // HTTP/2 headers are already always lower case
+ coyoteRequest.getTrailerFields().put(name, value);
+ }
} else {
coyoteRequest.getMimeHeaders().addValue(name).setString(value);
}
@@ -585,6 +589,11 @@ class Stream extends AbstractStream implements
HeaderEmitter {
final ByteBuffer getInputByteBuffer() {
+ // Avoid NPE if Stream has been closed on Stream specific thread
+ StreamInputBuffer inputBuffer = this.inputBuffer;
+ if (inputBuffer == null) {
+ return null;
+ }
return inputBuffer.getInBuffer();
}
@@ -615,6 +624,11 @@ class Stream extends AbstractStream implements
HeaderEmitter {
final void receivedData(int payloadSize) throws ConnectionException {
contentLengthReceived += payloadSize;
+ Request coyoteRequest = this.coyoteRequest;
+ // Avoid NPE if Stream has been closed on Stream specific thread
+ if (coyoteRequest == null) {
+ return;
+ }
long contentLengthHeader = coyoteRequest.getContentLengthLong();
if (contentLengthHeader > -1 && contentLengthReceived >
contentLengthHeader) {
throw new
ConnectionException(sm.getString("stream.header.contentLength",
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 312e2b9..7f012a4 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -95,6 +95,10 @@
<code>ServletInputStream.available()</code> to provide a more accurate
return value, particularly when end of stream has been reached. (markt)
</fix>
+ <fix>
+ Avoid several potential NPEs introduced in the changes in the previous
+ release to reduce the memory footprint of closed HTTP/2 streams.
(markt)
+ </fix>
</changelog>
</subsection>
<subsection name="WebSocket">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]