From 482f2c3a30f1ea339c7473bd03d49f1d38444d98 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Fri, 9 Feb 2018 13:17:14 -0800 Subject: [PATCH] Bug 1437080 P1 Correctly check cache related bit flags on HttpBaseChannel::mLoadFlags. r=valentin --- netwerk/protocol/http/HttpBaseChannel.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index 2cfceaec5f27..5106cab096fd 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -2808,6 +2808,16 @@ HttpBaseChannel::SetRedirectMode(uint32_t aMode) return NS_OK; } +namespace { + +bool +ContainsAllFlags(uint32_t aLoadFlags, uint32_t aMask) +{ + return (aLoadFlags & aMask) == aMask; +} + +} // anonymous namespace + NS_IMETHODIMP HttpBaseChannel::GetFetchCacheMode(uint32_t* aFetchCacheMode) { @@ -2820,15 +2830,16 @@ HttpBaseChannel::GetFetchCacheMode(uint32_t* aFetchCacheMode) } // Otherwise try to guess an appropriate cache mode from the load flags. - if (mLoadFlags & (INHIBIT_CACHING | LOAD_BYPASS_CACHE)) { + if (ContainsAllFlags(mLoadFlags, INHIBIT_CACHING | LOAD_BYPASS_CACHE)) { *aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_NO_STORE; - } else if (mLoadFlags & LOAD_BYPASS_CACHE) { + } else if (ContainsAllFlags(mLoadFlags, LOAD_BYPASS_CACHE)) { *aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_RELOAD; - } else if (mLoadFlags & VALIDATE_ALWAYS) { + } else if (ContainsAllFlags(mLoadFlags, VALIDATE_ALWAYS)) { *aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_NO_CACHE; - } else if (mLoadFlags & (LOAD_FROM_CACHE | nsICachingChannel::LOAD_ONLY_FROM_CACHE)) { + } else if (ContainsAllFlags(mLoadFlags, LOAD_FROM_CACHE | + nsICachingChannel::LOAD_ONLY_FROM_CACHE)) { *aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_ONLY_IF_CACHED; - } else if (mLoadFlags & LOAD_FROM_CACHE) { + } else if (ContainsAllFlags(mLoadFlags, LOAD_FROM_CACHE)) { *aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_FORCE_CACHE; } else { *aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_DEFAULT;