Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BEC12200B81 for ; Tue, 13 Sep 2016 20:32:43 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BBA96160AD2; Tue, 13 Sep 2016 18:32:43 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DA933160AAA for ; Tue, 13 Sep 2016 20:32:42 +0200 (CEST) Received: (qmail 57848 invoked by uid 500); 13 Sep 2016 18:32:42 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 57838 invoked by uid 99); 13 Sep 2016 18:32:42 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Sep 2016 18:32:41 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 75C071A523C for ; Tue, 13 Sep 2016 18:32:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.374 X-Spam-Level: X-Spam-Status: No, score=0.374 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id yS5sZijmVNEB for ; Tue, 13 Sep 2016 18:32:40 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with ESMTP id 46EAB5F64D for ; Tue, 13 Sep 2016 18:32:40 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 89F43E0069 for ; Tue, 13 Sep 2016 18:32:39 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 0AE8C3A01DD for ; Tue, 13 Sep 2016 18:32:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1760585 - in /httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http: impl/sync/ResponseEntityProxy.java io/EofSensorInputStream.java Date: Tue, 13 Sep 2016 18:32:38 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160913183239.0AE8C3A01DD@svn01-us-west.apache.org> archived-at: Tue, 13 Sep 2016 18:32:43 -0000 Author: olegk Date: Tue Sep 13 18:32:38 2016 New Revision: 1760585 URL: http://svn.apache.org/viewvc?rev=1760585&view=rev Log: HTTPCLIENT-1767: Null pointer dereference in EofSensorInputStream and ResponseEntityProxy EofSensorInputStream is generating NullPointerExceptions in some rare situations. This commit fixes that behaviour for the check methods by dereferencing the instance variable to a final local variable to ensure that if it is not null at the null guard, that it will be not null after that point also to successfully close/abort the stream In some rare cases, null parameters are sent to ReponseEntityProxy methods, this adds checks on those to ensure that the connections are still released, but the null variable is not dereferenced. Contributed by Peter Ansell Conflicts: httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/EofSensorInputStream.java Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java?rev=1760585&r1=1760584&r2=1760585&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java (original) +++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ResponseEntityProxy.java Tue Sep 13 18:32:38 2016 @@ -92,7 +92,9 @@ class ResponseEntityProxy extends HttpEn @Override public void writeTo(final OutputStream outstream) throws IOException { try { - super.writeTo(outstream); + if (outstream != null) { + super.writeTo(outstream); + } releaseConnection(); } catch (IOException | RuntimeException ex) { abortConnection(); @@ -107,7 +109,9 @@ class ResponseEntityProxy extends HttpEn try { // there may be some cleanup required, such as // reading trailers after the response body: - wrapped.close(); + if (wrapped != null) { + wrapped.close(); + } releaseConnection(); } catch (IOException | RuntimeException ex) { abortConnection(); @@ -125,7 +129,9 @@ class ResponseEntityProxy extends HttpEn // this assumes that closing the stream will // consume the remainder of the response body: try { - wrapped.close(); + if (wrapped != null) { + wrapped.close(); + } releaseConnection(); } catch (final SocketException ex) { if (open) { Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/EofSensorInputStream.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/EofSensorInputStream.java?rev=1760585&r1=1760584&r2=1760585&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/EofSensorInputStream.java (original) +++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/io/EofSensorInputStream.java Tue Sep 13 18:32:38 2016 @@ -193,14 +193,15 @@ public class EofSensorInputStream extend */ protected void checkEOF(final int eof) throws IOException { - if ((wrappedStream != null) && (eof < 0)) { + final InputStream toCheckStream = wrappedStream; + if ((toCheckStream != null) && (eof < 0)) { try { boolean scws = true; // should close wrapped stream? if (eofWatcher != null) { - scws = eofWatcher.eofDetected(wrappedStream); + scws = eofWatcher.eofDetected(toCheckStream); } if (scws) { - wrappedStream.close(); + toCheckStream.close(); } } finally { wrappedStream = null; @@ -221,14 +222,15 @@ public class EofSensorInputStream extend */ protected void checkClose() throws IOException { - if (wrappedStream != null) { + final InputStream toCloseStream = wrappedStream; + if (toCloseStream != null) { try { boolean scws = true; // should close wrapped stream? if (eofWatcher != null) { - scws = eofWatcher.streamClosed(wrappedStream); + scws = eofWatcher.streamClosed(toCloseStream); } if (scws) { - wrappedStream.close(); + toCloseStream.close(); } } finally { wrappedStream = null; @@ -251,14 +253,15 @@ public class EofSensorInputStream extend */ protected void checkAbort() throws IOException { - if (wrappedStream != null) { + final InputStream toAbortStream = wrappedStream; + if (toAbortStream != null) { try { boolean scws = true; // should close wrapped stream? if (eofWatcher != null) { - scws = eofWatcher.streamAbort(wrappedStream); + scws = eofWatcher.streamAbort(toAbortStream); } if (scws) { - wrappedStream.close(); + toAbortStream.close(); } } finally { wrappedStream = null;