From d2b480a8db36e8aa1710b88b3d3e7e8b008c49a3 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Mon, 4 May 2015 16:52:23 -0400 Subject: [PATCH] Bug 1161240 - Make sure that NS_CloneInputStream correctly deals with null input; r=froydnj --- xpcom/io/nsStreamUtils.cpp | 4 ++++ xpcom/tests/gtest/TestCloneInputStream.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/xpcom/io/nsStreamUtils.cpp b/xpcom/io/nsStreamUtils.cpp index e38c037302e7..e23cda49e07a 100644 --- a/xpcom/io/nsStreamUtils.cpp +++ b/xpcom/io/nsStreamUtils.cpp @@ -853,6 +853,10 @@ nsresult NS_CloneInputStream(nsIInputStream* aSource, nsIInputStream** aCloneOut, nsIInputStream** aReplacementOut) { + if (NS_WARN_IF(!aSource)) { + return NS_ERROR_FAILURE; + } + // Attempt to perform the clone directly on the source stream nsCOMPtr cloneable = do_QueryInterface(aSource); if (cloneable && cloneable->GetCloneable()) { diff --git a/xpcom/tests/gtest/TestCloneInputStream.cpp b/xpcom/tests/gtest/TestCloneInputStream.cpp index d9b2dc28dde2..633d207988f9 100644 --- a/xpcom/tests/gtest/TestCloneInputStream.cpp +++ b/xpcom/tests/gtest/TestCloneInputStream.cpp @@ -12,6 +12,14 @@ #include "nsStreamUtils.h" #include "nsStringStream.h" +TEST(CloneInputStream, InvalidInput) +{ + nsCOMPtr clone; + nsresult rv = NS_CloneInputStream(nullptr, getter_AddRefs(clone)); + ASSERT_TRUE(NS_FAILED(rv)); + ASSERT_FALSE(clone); +} + TEST(CloneInputStream, CloneableInput) { nsTArray inputData;