Skip to content

Commit

Permalink
#440: vmx_strchr() in netwerk/, security/
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Nov 14, 2017
1 parent dc55a36 commit 81e2358
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 40 deletions.
9 changes: 6 additions & 3 deletions netwerk/base/Predictor.cpp
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion netwerk/base/nsNetUtil.cpp
Expand Up @@ -66,6 +66,9 @@

#include <limits>

#include "mozilla-config.h"
#include "plvmx.h"

nsresult /*NS_NewChannelWithNodeAndTriggeringPrincipal */
NS_NewChannelWithTriggeringPrincipal(nsIChannel **outChannel,
nsIURI *aUri,
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion netwerk/base/nsProtocolProxyService.cpp
Expand Up @@ -34,6 +34,9 @@
#include "nsINetworkLinkService.h"
#include "nsIHttpChannelInternal.h"

#include "mozilla-config.h"
#include "plvmx.h"

//----------------------------------------------------------------------------

namespace mozilla {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions netwerk/base/nsStandardURL.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion netwerk/base/nsURLParsers.cpp
Expand Up @@ -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) {
Expand Down
13 changes: 8 additions & 5 deletions netwerk/mime/nsMIMEHeaderParamImpl.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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;
}

Expand Down
9 changes: 6 additions & 3 deletions netwerk/protocol/data/nsDataHandler.cpp
Expand Up @@ -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);

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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;

Expand All @@ -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';

Expand Down
7 changes: 5 additions & 2 deletions netwerk/protocol/http/nsHttp.cpp
Expand Up @@ -13,6 +13,9 @@
#include "mozilla/HashFunctions.h"
#include "nsCRT.h"

#include "mozilla-config.h"
#include "plvmx.h"

namespace mozilla {
namespace net {

Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 5 additions & 2 deletions netwerk/protocol/http/nsHttpChannel.cpp
Expand Up @@ -92,6 +92,9 @@
#include "nsICompressConvStats.h"
#include "mozilla/unused.h"

#include "mozilla-config.h"
#include "plvmx.h"

namespace mozilla { namespace net {

namespace {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
Expand Up @@ -29,6 +29,9 @@
#include "nsIURL.h"
#include "mozilla/Telemetry.h"

#include "mozilla-config.h"
#include "plvmx.h"

namespace mozilla {
namespace net {

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion netwerk/protocol/http/nsHttpChunkedDecoder.cpp
Expand Up @@ -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!
Expand Down
7 changes: 5 additions & 2 deletions netwerk/protocol/http/nsHttpHandler.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions netwerk/protocol/http/nsHttpHeaderArray.cpp
Expand Up @@ -11,6 +11,9 @@
#include "nsURLHelper.h"
#include "nsIHttpHeaderVisitor.h"

#include "mozilla-config.h"
#include "plvmx.h"

namespace mozilla {
namespace net {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 6 additions & 3 deletions netwerk/protocol/http/nsHttpResponseHead.cpp
Expand Up @@ -14,6 +14,9 @@
#include "nsURLHelper.h"
#include <algorithm>

#include "mozilla-config.h"
#include "plvmx.h"

namespace mozilla {
namespace net {

Expand Down Expand Up @@ -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();
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion netwerk/protocol/http/nsHttpTransaction.cpp
Expand Up @@ -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 = '*';
}
Expand Down

0 comments on commit 81e2358

Please sign in to comment.