Bug 1709559 - Avoid using PL_str implementations when fuzzing network. r=valentin,necko-reviewers,xpcom-reviewers,KrisWright

Differential Revision: https://phabricator.services.mozilla.com/D114347
This commit is contained in:
Christian Holler 2021-05-05 18:09:28 +00:00
parent f035a4f375
commit ad1556611a
23 changed files with 114 additions and 58 deletions

View File

@ -22,6 +22,7 @@
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsContentUtils.h"
#include "nsCRT.h"
#include "nsThreadUtils.h"
#include "nsQueryObject.h"
#include "nsSOCKSIOLayer.h"
@ -1141,7 +1142,7 @@ bool nsProtocolProxyService::CanUseProxy(nsIURI* aURI, int32_t defaultPort) {
// compare last |filter_host_len| bytes of target hostname.
//
const char* host_tail = host.get() + host_len - filter_host_len;
if (!PL_strncasecmp(host_tail, hinfo->name.host, filter_host_len)) {
if (!nsCRT::strncasecmp(host_tail, hinfo->name.host, filter_host_len)) {
// If the tail of the host string matches the filter
if (filter_host_len > 0 && hinfo->name.host[0] == '.') {
@ -1206,25 +1207,25 @@ const char* nsProtocolProxyService::ExtractProxyInfo(const char* start,
const char* type = nullptr;
switch (len) {
case 4:
if (PL_strncasecmp(start, kProxyType_HTTP, 4) == 0) {
if (nsCRT::strncasecmp(start, kProxyType_HTTP, 4) == 0) {
type = kProxyType_HTTP;
}
break;
case 5:
if (PL_strncasecmp(start, kProxyType_PROXY, 5) == 0) {
if (nsCRT::strncasecmp(start, kProxyType_PROXY, 5) == 0) {
type = kProxyType_HTTP;
} else if (PL_strncasecmp(start, kProxyType_SOCKS, 5) == 0) {
} else if (nsCRT::strncasecmp(start, kProxyType_SOCKS, 5) == 0) {
type = kProxyType_SOCKS4; // assume v4 for 4x compat
} else if (PL_strncasecmp(start, kProxyType_HTTPS, 5) == 0) {
} else if (nsCRT::strncasecmp(start, kProxyType_HTTPS, 5) == 0) {
type = kProxyType_HTTPS;
}
break;
case 6:
if (PL_strncasecmp(start, kProxyType_DIRECT, 6) == 0)
if (nsCRT::strncasecmp(start, kProxyType_DIRECT, 6) == 0)
type = kProxyType_DIRECT;
else if (PL_strncasecmp(start, kProxyType_SOCKS4, 6) == 0)
else if (nsCRT::strncasecmp(start, kProxyType_SOCKS4, 6) == 0)
type = kProxyType_SOCKS4;
else if (PL_strncasecmp(start, kProxyType_SOCKS5, 6) == 0)
else if (nsCRT::strncasecmp(start, kProxyType_SOCKS5, 6) == 0)
// map "SOCKS5" to "socks" to match contract-id of registered
// SOCKS-v5 socket provider.
type = kProxyType_SOCKS;

View File

@ -10,6 +10,7 @@
#include "nsSimpleURI.h"
#include "nscore.h"
#include "nsCRT.h"
#include "nsString.h"
#include "plstr.h"
#include "nsURLHelper.h"
@ -523,7 +524,7 @@ nsSimpleURI::SchemeIs(const char* i_Scheme, bool* o_Equals) {
// mScheme is guaranteed to be lower case.
if (*i_Scheme == *this_scheme || *i_Scheme == (*this_scheme - ('a' - 'A'))) {
*o_Equals = PL_strcasecmp(this_scheme, i_Scheme) == 0;
*o_Equals = nsCRT::strcasecmp(this_scheme, i_Scheme) == 0;
} else {
*o_Equals = false;
}

View File

@ -1010,7 +1010,7 @@ bool nsStandardURL::SegmentIs(const URLSegment& seg, const char* val,
// if the first |seg.mLen| chars of |val| match, then |val| must
// also be null terminated at |seg.mLen|.
if (ignoreCase) {
return !PL_strncasecmp(mSpec.get() + seg.mPos, val, seg.mLen) &&
return !nsCRT::strncasecmp(mSpec.get() + seg.mPos, val, seg.mLen) &&
(val[seg.mLen] == '\0');
}
@ -1030,7 +1030,7 @@ bool nsStandardURL::SegmentIs(const char* spec, const URLSegment& seg,
// if the first |seg.mLen| chars of |val| match, then |val| must
// also be null terminated at |seg.mLen|.
if (ignoreCase) {
return !PL_strncasecmp(spec + seg.mPos, val, seg.mLen) &&
return !nsCRT::strncasecmp(spec + seg.mPos, val, seg.mLen) &&
(val[seg.mLen] == '\0');
}
@ -1049,7 +1049,8 @@ bool nsStandardURL::SegmentIs(const URLSegment& seg1, const char* val,
return false;
}
if (ignoreCase) {
return !PL_strncasecmp(mSpec.get() + seg1.mPos, val + seg2.mPos, seg1.mLen);
return !nsCRT::strncasecmp(mSpec.get() + seg1.mPos, val + seg2.mPos,
seg1.mLen);
}
return !strncmp(mSpec.get() + seg1.mPos, val + seg2.mPos, seg1.mLen);

View File

@ -675,7 +675,8 @@ static void net_ParseMediaType(const nsACString& aMediaTypeStr,
const char* paramName = net_FindCharNotInSet(
start + curParamStart, start + curParamEnd, HTTP_LWS);
static const char charsetStr[] = "charset=";
if (PL_strncasecmp(paramName, charsetStr, sizeof(charsetStr) - 1) == 0) {
if (nsCRT::strncasecmp(paramName, charsetStr, sizeof(charsetStr) - 1) ==
0) {
charset = paramName + sizeof(charsetStr) - 1;
charsetEnd = start + curParamEnd;
typeHasCharset = true;

View File

@ -15,6 +15,7 @@
#include "nsProxyRelease.h"
#include "nsReadableUtils.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsNetCID.h"
#include "nsError.h"
#include "nsDNSPrefetch.h"
@ -1350,7 +1351,7 @@ uint16_t nsDNSService::GetAFForLookup(const nsACString& host, uint32_t flags) {
domainLen = end - domain;
if (domainLen && hostLen >= domainLen) {
const char* hostTail = hostStart.get() + hostLen - domainLen;
if (PL_strncasecmp(domain, hostTail, domainLen) == 0) {
if (nsCRT::strncasecmp(domain, hostTail, domainLen) == 0) {
// now, make sure either that the hostname is a direct match or
// that the hostname begins with a dot.
if (hostLen == domainLen || *hostTail == '.' ||

View File

@ -17,6 +17,7 @@
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIObserver.h"
#include "nsCRT.h"
#include "nsThreadUtils.h"
#include "nsProxyRelease.h"
#include "nsIStringBundle.h"
@ -147,7 +148,7 @@ static gint FileInfoComparator(gconstpointer a, gconstpointer b) {
return 1;
}
return strcasecmp(g_file_info_get_name(ia), g_file_info_get_name(ib));
return nsCRT::strcasecmp(g_file_info_get_name(ia), g_file_info_get_name(ib));
}
/* Declaration of mount callback functions */

View File

@ -86,8 +86,8 @@ static PLDHashNumber StringHash(const void* key) {
static bool StringCompare(const PLDHashEntryHdr* entry, const void* testKey) {
const void* entryKey = reinterpret_cast<const PLDHashEntryStub*>(entry)->key;
return PL_strcasecmp(reinterpret_cast<const char*>(entryKey),
reinterpret_cast<const char*>(testKey)) == 0;
return nsCRT::strcasecmp(reinterpret_cast<const char*>(entryKey),
reinterpret_cast<const char*>(testKey)) == 0;
}
static const PLDHashTableOps ops = {StringHash, StringCompare,
@ -271,7 +271,7 @@ const char* FindToken(const char* input, const char* token, const char* seps) {
const char* inputTop = input;
const char* inputEnd = input + inputLen - tokenLen;
for (; input <= inputEnd; ++input) {
if (PL_strncasecmp(input, token, tokenLen) == 0) {
if (nsCRT::strncasecmp(input, token, tokenLen) == 0) {
if (input > inputTop && !strchr(seps, *(input - 1))) continue;
if (input < inputEnd && !strchr(seps, *(input + tokenLen))) continue;
return input;
@ -853,8 +853,8 @@ void LogHeaders(const char* lineStart) {
while ((endOfLine = PL_strstr(lineStart, "\r\n"))) {
buf.Assign(lineStart, endOfLine - lineStart);
if (StaticPrefs::network_http_sanitize_headers_in_logs() &&
(PL_strcasestr(buf.get(), "authorization: ") ||
PL_strcasestr(buf.get(), "proxy-authorization: "))) {
(nsCRT::strcasestr(buf.get(), "authorization: ") ||
nsCRT::strcasestr(buf.get(), "proxy-authorization: "))) {
char* p = PL_strchr(buf.get(), ' ');
while (p && *++p) {
*p = '*';

View File

@ -8,6 +8,7 @@
#include "nsHttpBasicAuth.h"
#include "plstr.h"
#include "nsCRT.h"
#include "nsString.h"
#include "mozilla/Base64.h"
#include "mozilla/ClearOnShutdown.h"
@ -76,7 +77,7 @@ nsHttpBasicAuth::GenerateCredentials(
*aFlags = 0;
// we only know how to deal with Basic auth for http.
bool isBasicAuth = !PL_strncasecmp(challenge, "basic", 5);
bool isBasicAuth = !nsCRT::strncasecmp(challenge, "basic", 5);
NS_ENSURE_TRUE(isBasicAuth, NS_ERROR_UNEXPECTED);
// we work with UTF-8 around here

View File

@ -34,6 +34,7 @@
#include "nsIStreamListenerTee.h"
#include "nsISeekableStream.h"
#include "nsIProtocolProxyService2.h"
#include "nsCRT.h"
#include "nsMimeTypes.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
@ -3107,7 +3108,8 @@ nsresult nsHttpChannel::ProcessPartialContent(
Unused << mResponseHead->GetHeader(nsHttp::Content_Encoding, contentEncoding);
Unused << mCachedResponseHead->GetHeader(nsHttp::Content_Encoding,
cachedContentEncoding);
if (PL_strcasecmp(contentEncoding.get(), cachedContentEncoding.get()) != 0) {
if (nsCRT::strcasecmp(contentEncoding.get(), cachedContentEncoding.get()) !=
0) {
Cancel(NS_ERROR_INVALID_CONTENT_ENCODING);
return CallOnStartRequest();
}

View File

@ -11,6 +11,7 @@
#include "mozilla/Preferences.h"
#include "mozilla/StoragePrincipalHelper.h"
#include "nsHttpChannelAuthProvider.h"
#include "nsCRT.h"
#include "nsNetUtil.h"
#include "nsHttpHandler.h"
#include "nsIHttpAuthenticator.h"
@ -1089,7 +1090,7 @@ void nsHttpChannelAuthProvider::ParseRealm(const char* challenge,
// end-of-line, if the string is not quoted.
//
const char* p = PL_strcasestr(challenge, "realm=");
const char* p = nsCRT::strcasestr(challenge, "realm=");
if (p) {
bool has_quote = false;
p += 6;

View File

@ -31,6 +31,7 @@
#include "nsISSLSocketControl.h"
#include "nsISupportsPriority.h"
#include "nsITransportSecurityInfo.h"
#include "nsCRT.h"
#include "nsPreloadedStream.h"
#include "nsProxyRelease.h"
#include "nsSocketTransport2.h"
@ -1282,13 +1283,13 @@ nsresult nsHttpConnection::OnHeadersAvailable(nsAHttpTransaction* trans,
Unused << responseHead->GetHeader(nsHttp::Keep_Alive, keepAlive);
if (mUsingSpdyVersion == SpdyVersion::NONE) {
const char* cp = PL_strcasestr(keepAlive.get(), "timeout=");
const char* cp = nsCRT::strcasestr(keepAlive.get(), "timeout=");
if (cp)
mIdleTimeout = PR_SecondsToInterval((uint32_t)atoi(cp + 8));
else
mIdleTimeout = gHttpHandler->IdleTimeout() * mDefaultTimeoutFactor;
cp = PL_strcasestr(keepAlive.get(), "max=");
cp = nsCRT::strcasestr(keepAlive.get(), "max=");
if (cp) {
int maxUses = atoi(cp + 4);
if (maxUses > 0) {

View File

@ -185,7 +185,7 @@ nsHttpDigestAuth::GenerateCredentials(
*aFlags = 0;
bool isDigestAuth = !PL_strncasecmp(challenge, "digest ", 7);
bool isDigestAuth = !nsCRT::strncasecmp(challenge, "digest ", 7);
NS_ENSURE_TRUE(isDigestAuth, NS_ERROR_UNEXPECTED);
// IIS implementation requires extra quotes
@ -195,7 +195,7 @@ nsHttpDigestAuth::GenerateCredentials(
Unused << authChannel->GetServerResponseHeader(serverVal);
if (!serverVal.IsEmpty()) {
requireExtraQuotes =
!PL_strncasecmp(serverVal.get(), "Microsoft-IIS", 13);
!nsCRT::strncasecmp(serverVal.get(), "Microsoft-IIS", 13);
}
}

View File

@ -693,8 +693,9 @@ bool nsHttpHandler::IsAcceptableEncoding(const char* enc, bool isSecure) {
// gzip and deflate are inherently acceptable in modern HTTP - always
// process them if a stream converter can also be found.
if (!rv &&
(!PL_strcasecmp(enc, "gzip") || !PL_strcasecmp(enc, "deflate") ||
!PL_strcasecmp(enc, "x-gzip") || !PL_strcasecmp(enc, "x-deflate"))) {
(!nsCRT::strcasecmp(enc, "gzip") || !nsCRT::strcasecmp(enc, "deflate") ||
!nsCRT::strcasecmp(enc, "x-gzip") ||
!nsCRT::strcasecmp(enc, "x-deflate"))) {
rv = true;
}
LOG(("nsHttpHandler::IsAceptableEncoding %s https=%d %d\n", enc, isSecure,

View File

@ -31,6 +31,7 @@
#include "mozilla/Tokenizer.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/Unused.h"
#include "nsCRT.h"
#include "nsNetUtil.h"
#include "nsIChannel.h"
#include "nsUnicharUtils.h"
@ -171,7 +172,7 @@ nsHttpNTLMAuth::ChallengeReceived(nsIHttpAuthenticableChannel* channel,
// Start a new auth sequence if the challenge is exactly "NTLM".
// If native NTLM auth apis are available and enabled through prefs,
// try to use them.
if (PL_strcasecmp(challenge, "NTLM") == 0) {
if (nsCRT::strcasecmp(challenge, "NTLM") == 0) {
nsCOMPtr<nsIAuthModule> module;
// Check to see if we should default to our generic NTLM auth module
@ -285,7 +286,7 @@ nsHttpNTLMAuth::GenerateCredentials(nsIHttpAuthenticableChannel* authChannel,
Maybe<nsTArray<uint8_t>> certArray;
// initial challenge
if (PL_strcasecmp(challenge, "NTLM") == 0) {
if (nsCRT::strcasecmp(challenge, "NTLM") == 0) {
// NTLM service name format is 'HTTP@host' for both http and https
nsCOMPtr<nsIURI> uri;
rv = authChannel->GetURI(getter_AddRefs(uri));

View File

@ -13,6 +13,7 @@
#include "nsPrintfCString.h"
#include "prtime.h"
#include "plstr.h"
#include "nsCRT.h"
#include "nsURLHelper.h"
#include "CacheControlParser.h"
#include <algorithm>
@ -1098,7 +1099,7 @@ void nsHttpResponseHead::ParseVersion(const char* str) {
Tokenizer t(str, nullptr, "");
// make sure we have HTTP at the beginning
if (!t.CheckWord("HTTP")) {
if (PL_strncasecmp(str, "ICY ", 4) == 0) {
if (nsCRT::strncasecmp(str, "ICY ", 4) == 0) {
// ShoutCast ICY is HTTP/1.0-like. Assume it is HTTP/1.0.
LOG(("Treating ICY as HTTP 1.0\n"));
mVersion = HttpVersion::v1_0;

View File

@ -1868,13 +1868,14 @@ char* nsHttpTransaction::LocateHttpStart(char* buf, uint32_t len,
static const uint32_t ICYHeaderLen = sizeof(ICYHeader) - 1;
if (aAllowPartialMatch && (len < HTTPHeaderLen))
return (PL_strncasecmp(buf, HTTPHeader, len) == 0) ? buf : nullptr;
return (nsCRT::strncasecmp(buf, HTTPHeader, len) == 0) ? buf : nullptr;
// mLineBuf can contain partial match from previous search
if (!mLineBuf.IsEmpty()) {
MOZ_ASSERT(mLineBuf.Length() < HTTPHeaderLen);
int32_t checkChars = std::min(len, HTTPHeaderLen - mLineBuf.Length());
if (PL_strncasecmp(buf, HTTPHeader + mLineBuf.Length(), checkChars) == 0) {
if (nsCRT::strncasecmp(buf, HTTPHeader + mLineBuf.Length(), checkChars) ==
0) {
mLineBuf.Append(buf, checkChars);
if (mLineBuf.Length() == HTTPHeaderLen) {
// We've found whole HTTPHeader sequence. Return pointer at the
@ -1891,8 +1892,8 @@ char* nsHttpTransaction::LocateHttpStart(char* buf, uint32_t len,
bool firstByte = true;
while (len > 0) {
if (PL_strncasecmp(buf, HTTPHeader,
std::min<uint32_t>(len, HTTPHeaderLen)) == 0) {
if (nsCRT::strncasecmp(buf, HTTPHeader,
std::min<uint32_t>(len, HTTPHeaderLen)) == 0) {
if (len < HTTPHeaderLen) {
// partial HTTPHeader sequence found
// save partial match to mLineBuf
@ -1910,7 +1911,7 @@ char* nsHttpTransaction::LocateHttpStart(char* buf, uint32_t len,
// other browsers
if (firstByte && !mInvalidResponseBytesRead && len >= HTTP2HeaderLen &&
(PL_strncasecmp(buf, HTTP2Header, HTTP2HeaderLen) == 0)) {
(nsCRT::strncasecmp(buf, HTTP2Header, HTTP2HeaderLen) == 0)) {
LOG(("nsHttpTransaction:: Identified HTTP/2.0 treating as 1.x\n"));
return buf;
}
@ -1920,7 +1921,7 @@ char* nsHttpTransaction::LocateHttpStart(char* buf, uint32_t len,
// other browsers
if (firstByte && !mInvalidResponseBytesRead && len >= HTTP3HeaderLen &&
(PL_strncasecmp(buf, HTTP3Header, HTTP3HeaderLen) == 0)) {
(nsCRT::strncasecmp(buf, HTTP3Header, HTTP3HeaderLen) == 0)) {
LOG(("nsHttpTransaction:: Identified HTTP/3.0 treating as 1.x\n"));
return buf;
}
@ -1930,7 +1931,7 @@ char* nsHttpTransaction::LocateHttpStart(char* buf, uint32_t len,
// as HTTP/1.0 in nsHttpResponseHead::ParseVersion
if (firstByte && !mInvalidResponseBytesRead && len >= ICYHeaderLen &&
(PL_strncasecmp(buf, ICYHeader, ICYHeaderLen) == 0)) {
(nsCRT::strncasecmp(buf, ICYHeader, ICYHeaderLen) == 0)) {
LOG(("nsHttpTransaction:: Identified ICY treating as HTTP/1.0\n"));
return buf;
}

View File

@ -3721,7 +3721,7 @@ WebSocketChannel::OnStartRequest(nsIRequest* aRequest) {
if (!respUpgrade.IsEmpty()) {
val = respUpgrade.BeginWriting();
while ((token = nsCRT::strtok(val, ", \t", &val))) {
if (PL_strcasecmp(token, "Websocket") == 0) {
if (nsCRT::strcasecmp(token, "Websocket") == 0) {
rv = NS_OK;
break;
}
@ -3745,7 +3745,7 @@ WebSocketChannel::OnStartRequest(nsIRequest* aRequest) {
if (!respConnection.IsEmpty()) {
val = respConnection.BeginWriting();
while ((token = nsCRT::strtok(val, ", \t", &val))) {
if (PL_strcasecmp(token, "Upgrade") == 0) {
if (nsCRT::strcasecmp(token, "Upgrade") == 0) {
rv = NS_OK;
break;
}

View File

@ -8,6 +8,7 @@
#include "nsMemory.h"
#include "plstr.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsError.h"
#include "nsStreamUtils.h"
#include "nsStringStream.h"
@ -89,21 +90,21 @@ NS_IMETHODIMP
nsHTTPCompressConv::AsyncConvertData(const char* aFromType, const char* aToType,
nsIStreamListener* aListener,
nsISupports* aCtxt) {
if (!PL_strncasecmp(aFromType, HTTP_COMPRESS_TYPE,
sizeof(HTTP_COMPRESS_TYPE) - 1) ||
!PL_strncasecmp(aFromType, HTTP_X_COMPRESS_TYPE,
sizeof(HTTP_X_COMPRESS_TYPE) - 1)) {
if (!nsCRT::strncasecmp(aFromType, HTTP_COMPRESS_TYPE,
sizeof(HTTP_COMPRESS_TYPE) - 1) ||
!nsCRT::strncasecmp(aFromType, HTTP_X_COMPRESS_TYPE,
sizeof(HTTP_X_COMPRESS_TYPE) - 1)) {
mMode = HTTP_COMPRESS_COMPRESS;
} else if (!PL_strncasecmp(aFromType, HTTP_GZIP_TYPE,
sizeof(HTTP_GZIP_TYPE) - 1) ||
!PL_strncasecmp(aFromType, HTTP_X_GZIP_TYPE,
sizeof(HTTP_X_GZIP_TYPE) - 1)) {
} else if (!nsCRT::strncasecmp(aFromType, HTTP_GZIP_TYPE,
sizeof(HTTP_GZIP_TYPE) - 1) ||
!nsCRT::strncasecmp(aFromType, HTTP_X_GZIP_TYPE,
sizeof(HTTP_X_GZIP_TYPE) - 1)) {
mMode = HTTP_COMPRESS_GZIP;
} else if (!PL_strncasecmp(aFromType, HTTP_DEFLATE_TYPE,
sizeof(HTTP_DEFLATE_TYPE) - 1)) {
} else if (!nsCRT::strncasecmp(aFromType, HTTP_DEFLATE_TYPE,
sizeof(HTTP_DEFLATE_TYPE) - 1)) {
mMode = HTTP_COMPRESS_DEFLATE;
} else if (!PL_strncasecmp(aFromType, HTTP_BROTLI_TYPE,
sizeof(HTTP_BROTLI_TYPE) - 1)) {
} else if (!nsCRT::strncasecmp(aFromType, HTTP_BROTLI_TYPE,
sizeof(HTTP_BROTLI_TYPE) - 1)) {
mMode = HTTP_COMPRESS_BROTLI;
}
LOG(("nsHttpCompresssConv %p AsyncConvertData %s %s mode %d\n", this,

View File

@ -561,10 +561,10 @@ bool nsUnknownDecoder::SniffForHTML(nsIRequest* aRequest) {
uint32_t bufSize = end - str;
// We use sizeof(_tagstr) below because that's the length of _tagstr
// with the one char " " or ">" appended.
#define MATCHES_TAG(_tagstr) \
(bufSize >= sizeof(_tagstr) && \
(PL_strncasecmp(str, _tagstr " ", sizeof(_tagstr)) == 0 || \
PL_strncasecmp(str, _tagstr ">", sizeof(_tagstr)) == 0))
#define MATCHES_TAG(_tagstr) \
(bufSize >= sizeof(_tagstr) && \
(nsCRT::strncasecmp(str, _tagstr " ", sizeof(_tagstr)) == 0 || \
nsCRT::strncasecmp(str, _tagstr ">", sizeof(_tagstr)) == 0))
if (MATCHES_TAG("html") || MATCHES_TAG("frameset") || MATCHES_TAG("body") ||
MATCHES_TAG("head") || MATCHES_TAG("script") || MATCHES_TAG("iframe") ||

View File

@ -5,6 +5,7 @@
#include "nsWifiMonitor.h"
#include "nsWifiAccessPoint.h"
#include "nsCRT.h"
#include "nsServiceManagerUtils.h"
#include "nsComponentManagerUtils.h"
@ -35,7 +36,8 @@ static nsWifiAccessPoint* do_parse_str(char* bssid_str, char* essid_str,
int signal = 0;
uint32_t strength_vals_count = sizeof(strength_vals) / sizeof(val_strength_t);
for (uint32_t i = 0; i < strength_vals_count; i++) {
if (!strncasecmp(strength, strength_vals[i].strength_name, DLADM_STRSIZE)) {
if (!nsCRT::strncasecmp(strength, strength_vals[i].strength_name,
DLADM_STRSIZE)) {
signal = strength_vals[i].signal_value;
break;
}

View File

@ -41,13 +41,25 @@ class nsCRT {
/// Case-insensitive string comparison.
static int32_t strcasecmp(const char* aStr1, const char* aStr2) {
/* Some functions like `PL_strcasecmp` are reimplementations
* of the their native POSIX counterparts, which breaks libFuzzer.
* For this purpose, we use the natives instead when fuzzing.
*/
#if defined(LIBFUZZER) && defined(LINUX)
return int32_t(::strcasecmp(aStr1, aStr2));
#else
return int32_t(PL_strcasecmp(aStr1, aStr2));
#endif
}
/// Case-insensitive string comparison with length
static int32_t strncasecmp(const char* aStr1, const char* aStr2,
uint32_t aMaxLen) {
#if defined(LIBFUZZER) && defined(LINUX)
int32_t result = int32_t(::strncasecmp(aStr1, aStr2, aMaxLen));
#else
int32_t result = int32_t(PL_strncasecmp(aStr1, aStr2, aMaxLen));
#endif
// Egads. PL_strncasecmp is returning *very* negative numbers.
// Some folks expect -1,0,1, so let's temper its enthusiasm.
if (result < 0) {
@ -56,6 +68,15 @@ class nsCRT {
return result;
}
/// Case-insensitive substring search.
static char* strcasestr(const char* aStr1, const char* aStr2) {
#if defined(LIBFUZZER) && defined(LINUX)
return const_cast<char*>(::strcasestr(aStr1, aStr2));
#else
return PL_strcasestr(aStr1, aStr2);
#endif
}
/**
How to use this fancy (thread-safe) version of strtok:

View File

@ -13,10 +13,23 @@
int nsCaseInsensitiveCStringComparator(const char* aLhs, const char* aRhs,
uint32_t aLhsLength,
uint32_t aRhsLength) {
#if defined(LIBFUZZER) && defined(LINUX)
// Make sure libFuzzer can see this string compare by calling the POSIX
// native function which is intercepted. We also call this if the lengths
// don't match so libFuzzer can at least see a partial string, but we throw
// away the result afterwards again.
int32_t result =
int32_t(strncasecmp(aLhs, aRhs, std::min(aLhsLength, aRhsLength)));
if (aLhsLength != aRhsLength) {
return (aLhsLength > aRhsLength) ? 1 : -1;
}
#else
if (aLhsLength != aRhsLength) {
return (aLhsLength > aRhsLength) ? 1 : -1;
}
int32_t result = int32_t(PL_strncasecmp(aLhs, aRhs, aLhsLength));
#endif
// Egads. PL_strncasecmp is returning *very* negative numbers.
// Some folks expect -1,0,1, so let's temper its enthusiasm.
if (result < 0) {

View File

@ -225,7 +225,11 @@ static
bool aIgnoreCase) {
int32_t result = 0;
if (aIgnoreCase)
# if defined(LIBFUZZER) && defined(LINUX)
result = int32_t(strncasecmp(aStr1, aStr2, aCount));
# else
result = int32_t(PL_strncasecmp(aStr1, aStr2, aCount));
# endif
else
result = nsCharTraits<char>::compare(aStr1, aStr2, aCount);