#440: vmx_strchr() in netwerk/, security/

This commit is contained in:
Cameron Kaiser 2017-11-13 21:36:46 -08:00
parent dc55a36a8c
commit 81e2358bec
18 changed files with 82 additions and 40 deletions

View File

@ -49,6 +49,9 @@
static const int32_t ANDROID_23_VERSION = 10;
#endif
#include "mozilla-config.h"
#include "plvmx.h"
using namespace mozilla;
namespace mozilla {
@ -1683,7 +1686,7 @@ Predictor::ParseMetaDataEntry(const char *key, const char *value, nsIURI **uri,
PREDICTOR_LOG(("Predictor::ParseMetaDataEntry key=%s value=%s",
key ? key : "", value));
const char *comma = strchr(value, ',');
const char *comma = VMX_STRCHR(value, ',');
if (!comma) {
PREDICTOR_LOG((" could not find first comma"));
return false;
@ -1699,7 +1702,7 @@ Predictor::ParseMetaDataEntry(const char *key, const char *value, nsIURI **uri,
}
value = comma + 1;
comma = strchr(value, ',');
comma = VMX_STRCHR(value, ',');
if (!comma) {
PREDICTOR_LOG((" could not find second comma"));
return false;
@ -1709,7 +1712,7 @@ Predictor::ParseMetaDataEntry(const char *key, const char *value, nsIURI **uri,
PREDICTOR_LOG((" hitCount -> %u", hitCount));
value = comma + 1;
comma = strchr(value, ',');
comma = VMX_STRCHR(value, ',');
if (!comma) {
PREDICTOR_LOG((" could not find third comma"));
return false;

View File

@ -66,6 +66,9 @@
#include <limits>
#include "mozilla-config.h"
#include "plvmx.h"
nsresult /*NS_NewChannelWithNodeAndTriggeringPrincipal */
NS_NewChannelWithTriggeringPrincipal(nsIChannel **outChannel,
nsIURI *aUri,
@ -2133,7 +2136,7 @@ nsresult
NS_GenerateHostPort(const nsCString& host, int32_t port,
nsACString &hostLine)
{
if (strchr(host.get(), ':')) {
if (VMX_STRCHR(host.get(), ':')) {
// host is an IPv6 address literal and must be encapsulated in []'s
hostLine.Assign('[');
// scope id is not needed for Host header.

View File

@ -34,6 +34,9 @@
#include "nsINetworkLinkService.h"
#include "nsIHttpChannelInternal.h"
#include "mozilla-config.h"
#include "plvmx.h"
//----------------------------------------------------------------------------
namespace mozilla {
@ -916,7 +919,7 @@ nsProtocolProxyService::ExtractProxyInfo(const char *start,
// www.example.com:8080
if (start < end) {
host = start;
hostEnd = strchr(host, ':');
hostEnd = VMX_STRCHR(host, ':');
if (!hostEnd || hostEnd > end) {
hostEnd = end;
// no port, so assume default

View File

@ -25,6 +25,9 @@
#include "mozilla/dom/EncodingUtils.h"
#include "nsContentUtils.h"
#include "mozilla-config.h"
#include "plvmx.h"
using mozilla::dom::EncodingUtils;
using namespace mozilla::ipc;
@ -1695,7 +1698,7 @@ nsStandardURL::SetHost(const nsACString &input)
// For consistency with SetSpec/nsURLParsers, don't allow spaces
// in the hostname.
if (strchr(host, ' '))
if (VMX_STRCHR(host, ' '))
return NS_ERROR_MALFORMED_URI;
InvalidateCache();
@ -2194,7 +2197,7 @@ nsStandardURL::Resolve(const nsACString &in, nsACString &out)
// locate result path
resultPath = PL_strstr(result, "://");
if (resultPath) {
resultPath = PL_strchr(resultPath + 3, '/');
resultPath = VMX_STRCHR(resultPath + 3, '/');
if (resultPath)
net_CoalesceDirs(coalesceFlag,resultPath);
}

View File

@ -665,7 +665,7 @@ nsStdURLParser::ParseAfterScheme(const char *spec, int32_t specLen,
const char *end = spec + specLen;
const char *p;
for (p = spec + nslash; p < end; ++p) {
if (strchr("/?#;", *p))
if (VMX_STRCHR("/?#;", *p))
break;
}
switch (nslash) {

View File

@ -24,6 +24,9 @@
#include "nsIUnicodeDecoder.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla-config.h"
#include "plvmx.h"
using mozilla::dom::EncodingUtils;
// static functions declared below are moved from mailnews/mime/src/comi18n.cpp
@ -558,8 +561,8 @@ nsMIMEHeaderParamImpl::DoParameterInternal(const char *aHeaderValue,
// in quotes (quotes required even if lang is blank)
if (caseB || (caseCStart && acceptContinuations)) {
// look for single quotation mark(')
const char *sQuote1 = PL_strchr(valueStart, 0x27);
const char *sQuote2 = sQuote1 ? PL_strchr(sQuote1 + 1, 0x27) : nullptr;
const char *sQuote1 = VMX_STRCHR(valueStart, 0x27);
const char *sQuote2 = sQuote1 ? VMX_STRCHR(sQuote1 + 1, 0x27) : nullptr;
// Two single quotation marks must be present even in
// absence of charset and lang.
@ -750,7 +753,7 @@ internalDecodeRFC2047Header(const char* aHeaderVal, const char* aDefaultCharset,
Is7bitNonAsciiString(aHeaderVal, strlen(aHeaderVal))))) {
DecodeRFC2047Str(aHeaderVal, aDefaultCharset, aOverrideCharset, aResult);
} else if (aEatContinuations &&
(PL_strchr(aHeaderVal, '\n') || PL_strchr(aHeaderVal, '\r'))) {
(VMX_STRCHR(aHeaderVal, '\n') || VMX_STRCHR(aHeaderVal, '\r'))) {
aResult = aHeaderVal;
} else {
aEatContinuations = false;
@ -1191,7 +1194,7 @@ nsresult DecodeRFC2047Str(const char *aHeader, const char *aDefaultCharset,
if (isLastEncodedWord) {
// See if it's all whitespace.
for (q = begin; q < p; ++q) {
if (!PL_strchr(" \t\r\n", *q)) break;
if (!VMX_STRCHR(" \t\r\n", *q)) break;
}
}
@ -1217,7 +1220,7 @@ nsresult DecodeRFC2047Str(const char *aHeader, const char *aDefaultCharset,
charsetStart = p;
charsetEnd = 0;
for (q = p; *q != '?'; q++) {
if (*q <= ' ' || PL_strchr(especials, *q)) {
if (*q <= ' ' || VMX_STRCHR(especials, *q)) {
goto badsyntax;
}

View File

@ -10,6 +10,9 @@
#include "DataChannelChild.h"
#include "plstr.h"
#include "mozilla-config.h"
#include "plvmx.h"
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
////////////////////////////////////////////////////////////////////////////////
@ -168,8 +171,8 @@ nsDataHandler::ParseURI(nsCString& spec,
buffer += 5;
// First, find the start of the data
char *comma = strchr(buffer, ',');
char *hash = strchr(buffer, '#');
char *comma = VMX_STRCHR(buffer, ',');
char *hash = VMX_STRCHR(buffer, '#');
if (!comma || (hash && hash < comma))
return NS_ERROR_MALFORMED_URI;
@ -195,7 +198,7 @@ nsDataHandler::ParseURI(nsCString& spec,
contentCharset.AssignLiteral("US-ASCII");
} else {
// everything else is content type
char *semiColon = (char *) strchr(buffer, ';');
char *semiColon = (char *) VMX_STRCHR(buffer, ';');
if (semiColon)
*semiColon = '\0';

View File

@ -13,6 +13,9 @@
#include "mozilla/HashFunctions.h"
#include "nsCRT.h"
#include "mozilla-config.h"
#include "plvmx.h"
namespace mozilla {
namespace net {
@ -281,9 +284,9 @@ nsHttp::FindToken(const char *input, const char *token, const char *seps)
const char *inputEnd = input + inputLen - tokenLen;
for (; input <= inputEnd; ++input) {
if (PL_strncasecmp(input, token, tokenLen) == 0) {
if (input > inputTop && !strchr(seps, *(input - 1)))
if (input > inputTop && !VMX_STRCHR(seps, *(input - 1)))
continue;
if (input < inputEnd && !strchr(seps, *(input + tokenLen)))
if (input < inputEnd && !VMX_STRCHR(seps, *(input + tokenLen)))
continue;
return input;
}

View File

@ -92,6 +92,9 @@
#include "nsICompressConvStats.h"
#include "mozilla/unused.h"
#include "mozilla-config.h"
#include "plvmx.h"
namespace mozilla { namespace net {
namespace {
@ -3804,7 +3807,7 @@ nsHttpChannel::AssembleCacheKey(const char *spec, uint32_t postID,
}
// Strip any trailing #ref from the URL before using it as the key
const char *p = strchr(spec, '#');
const char *p = VMX_STRCHR(spec, '#');
if (p)
cacheKey.Append(spec, p - spec);
else
@ -4450,7 +4453,7 @@ GetAuthType(const char *challenge, nsCString &authType)
const char *p;
// get the challenge type
if ((p = strchr(challenge, ' ')) != nullptr)
if ((p = VMX_STRCHR(challenge, ' ')) != nullptr)
authType.Assign(challenge, p - challenge);
else
authType.Assign(challenge);

View File

@ -29,6 +29,9 @@
#include "nsIURL.h"
#include "mozilla/Telemetry.h"
#include "mozilla-config.h"
#include "plvmx.h"
namespace mozilla {
namespace net {
@ -498,7 +501,7 @@ nsHttpChannelAuthProvider::GetCredentials(const char *challenges,
const char *p = eol + 1;
// get the challenge string (LF separated -- see nsHttpHeaderArray)
if ((eol = strchr(p, '\n')) != nullptr)
if ((eol = VMX_STRCHR(p, '\n')) != nullptr)
challenge.Assign(p, eol - p);
else
challenge.Assign(p);
@ -878,7 +881,7 @@ GetAuthType(const char *challenge, nsCString &authType)
const char *p;
// get the challenge type
if ((p = strchr(challenge, ' ')) != nullptr)
if ((p = VMX_STRCHR(challenge, ' ')) != nullptr)
authType.Assign(challenge, p - challenge);
else
authType.Assign(challenge);
@ -975,7 +978,7 @@ nsHttpChannelAuthProvider::ParseRealm(const char *challenge,
}
else {
// realm given without quotes
end = strchr(p, ' ');
end = VMX_STRCHR(p, ' ');
if (end)
realm.Assign(p, end - p);
else

View File

@ -132,7 +132,7 @@ nsHttpChunkedDecoder::ParseChunkRemaining(char *buf,
unsigned long parsedval; // could be 64 bit, could be 32
// ignore any chunk-extensions
if ((p = PL_strchr(buf, ';')) != nullptr)
if ((p = VMX_STRCHR(buf, ';')) != nullptr)
*p = 0;
// mChunkRemaining is an uint32_t!

View File

@ -71,6 +71,9 @@
#include "nsCocoaFeatures.h"
#endif
#include "mozilla-config.h"
#include "plvmx.h"
//-----------------------------------------------------------------------------
#include "mozilla/net/HttpChannelChild.h"
#include "OptimizedFor.h" // 10.4Fx
@ -1687,9 +1690,9 @@ CanonicalizeLanguageTag(char *languageTag)
bool isFirst = true;
bool seenSingleton = false;
while (*s != '\0') {
char *subTagEnd = strchr(s, '-');
char *subTagEnd = VMX_STRCHR(s, '-');
if (subTagEnd == nullptr) {
subTagEnd = strchr(s, '\0');
subTagEnd = VMX_STRCHR(s, '\0');
}
if (isFirst) {

View File

@ -11,6 +11,9 @@
#include "nsURLHelper.h"
#include "nsIHttpHeaderVisitor.h"
#include "mozilla-config.h"
#include "plvmx.h"
namespace mozilla {
namespace net {
@ -173,7 +176,7 @@ nsHttpHeaderArray::ParseHeaderLine(const char *line,
// We skip over mal-formed headers in the hope that we'll still be able to
// do something useful with the response.
char *p = (char *) strchr(line, ':');
char *p = (char *) VMX_STRCHR(line, ':');
if (!p) {
LOG(("malformed header [%s]: no colon\n", line));
return NS_OK;
@ -217,7 +220,7 @@ nsHttpHeaderArray::ParseHeaderSet(char *buffer)
nsHttpAtom hdr;
char *val;
while (buffer) {
char *eof = strchr(buffer, '\r');
char *eof = VMX_STRCHR(buffer, '\r');
if (!eof) {
break;
}

View File

@ -14,6 +14,9 @@
#include "nsURLHelper.h"
#include <algorithm>
#include "mozilla-config.h"
#include "plvmx.h"
namespace mozilla {
namespace net {
@ -299,7 +302,7 @@ nsHttpResponseHead::ParseStatusLine(const char *line)
// HTTP-Version
ParseVersion(line);
if ((mVersion == NS_HTTP_VERSION_0_9) || !(line = PL_strchr(line, ' '))) {
if ((mVersion == NS_HTTP_VERSION_0_9) || !(line = VMX_STRCHR(line, ' '))) {
mStatus = 200;
AssignDefaultStatusText();
}
@ -312,7 +315,7 @@ nsHttpResponseHead::ParseStatusLine(const char *line)
}
// Reason-Phrase is whatever is remaining of the line
if (!(line = PL_strchr(line, ' '))) {
if (!(line = VMX_STRCHR(line, ' '))) {
AssignDefaultStatusText();
}
else
@ -770,7 +773,7 @@ nsHttpResponseHead::ParseVersion(const char *str)
return;
}
char *p = PL_strchr(str, '.');
char *p = VMX_STRCHR(str, '.');
if (p == nullptr) {
LOG(("mal-formed server version; assuming HTTP/1.0\n"));
mVersion = NS_HTTP_VERSION_1_0;

View File

@ -71,7 +71,7 @@ LogHeaders(const char *lineStart)
buf.Assign(lineStart, endOfLine - lineStart);
if (PL_strcasestr(buf.get(), "authorization: ") ||
PL_strcasestr(buf.get(), "proxy-authorization: ")) {
char *p = PL_strchr(PL_strchr(buf.get(), ' ') + 1, ' ');
char *p = VMX_STRCHR(VMX_STRCHR(buf.get(), ' ') + 1, ' ');
while (p && *++p)
*p = '*';
}

View File

@ -902,12 +902,12 @@ nsMultiMixedConv::OnStartRequest(nsIRequest *request, nsISupports *ctxt) {
return NS_ERROR_FAILURE;
}
bndry = strchr(bndry, '=');
bndry = VMX_STRCHR(bndry, '=');
if (!bndry) return NS_ERROR_FAILURE;
bndry++; // move past the equals sign
char *attrib = (char *) strchr(bndry, ';');
char *attrib = (char *) VMX_STRCHR(bndry, ';');
if (attrib) *attrib = '\0';
nsAutoCString boundaryString(bndry);
@ -1219,7 +1219,7 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr,
mResponseHead->ParseHeaderLine(tmpHeader.get());
}
char *colon = (char *) strchr(cursor, ':');
char *colon = (char *) VMX_STRCHR(cursor, ':');
if (colon) {
*colon = '\0';
nsAutoCString headerStr(cursor);
@ -1258,12 +1258,12 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr,
// something like: Content-range: bytes 7000-7999/8000
char* tmpPtr;
tmpPtr = (char *) strchr(colon + 1, '/');
tmpPtr = (char *) VMX_STRCHR(colon + 1, '/');
if (tmpPtr)
*tmpPtr = '\0';
// pass the bytes-unit and the SP
char *range = (char *) strchr(colon + 2, ' ');
char *range = (char *) VMX_STRCHR(colon + 2, ' ');
if (!range)
return NS_ERROR_FAILURE;
@ -1275,7 +1275,7 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr,
mByteRangeStart = mByteRangeEnd = 0;
}
else {
tmpPtr = (char *) strchr(range, '-');
tmpPtr = (char *) VMX_STRCHR(range, '-');
if (!tmpPtr)
return NS_ERROR_FAILURE;

View File

@ -40,6 +40,9 @@
#include "nsDirectoryServiceDefs.h"
#endif
#include "mozilla-config.h"
#include "plvmx.h"
#define NS_MOZICON_SCHEME "moz-icon:"
static const char kFileProtocol[] = "file://";
@ -54,7 +57,7 @@ FileSystemDataSource::isFileURI(nsIRDFResource *r)
if ((uri) && (!strncmp(uri, kFileProtocol, sizeof(kFileProtocol) - 1)))
{
// XXX HACK HACK HACK
if (!strchr(uri, '#'))
if (!VMX_STRCHR(uri, '#'))
{
isFileURIFlag = true;
}

View File

@ -17,6 +17,9 @@
#include "seccomon.h"
#include "sechash.h"
#include "mozilla-config.h"
#include "plvmx.h"
#include "StaticHPKPins.h" // autogenerated by genHPKPStaticpins.js
using namespace mozilla;
@ -174,7 +177,7 @@ FindPinningInformation(const char* hostname, mozilla::pkix::Time time,
char* evalHost = const_cast<char*>(hostname);
char* evalPart;
// Notice how the (xx = strchr) prevents pins for unqualified domain names.
while (!foundEntry && (evalPart = strchr(evalHost, '.'))) {
while (!foundEntry && (evalPart = VMX_STRCHR(evalHost, '.'))) {
MOZ_LOG(gPublicKeyPinningLog, LogLevel::Debug,
("pkpin: Querying pinsets for host: '%s'\n", evalHost));
// Attempt dynamic pins first