Bug 1271501 - Downgrade unnecessarily strong reinterpret_casts in PSM. r=keeler

These reinterpret_casts can be static_casts or const_casts instead.

MozReview-Commit-ID: 1KQDWHO9CGS
This commit is contained in:
Cykesiopka
2016-05-18 18:58:41 -07:00
parent 3745ea3b06
commit c42e21296a
10 changed files with 54 additions and 45 deletions

View File

@@ -633,7 +633,7 @@ VerifyCertificate(CERTCertificate* signerCert, void* voidContext, void* pinArg)
return NS_ERROR_INVALID_ARG;
}
const VerifyCertificateContext& context =
*reinterpret_cast<const VerifyCertificateContext*>(voidContext);
*static_cast<const VerifyCertificateContext*>(voidContext);
AppTrustDomain trustDomain(context.builtChain, pinArg);
if (trustDomain.SetTrustedRoot(context.trustedRoot) != SECSuccess) {

View File

@@ -649,7 +649,7 @@ void
CertBlocklist::PreferenceChanged(const char* aPref, void* aClosure)
{
CertBlocklist* blocklist = reinterpret_cast<CertBlocklist*>(aClosure);
auto blocklist = static_cast<CertBlocklist*>(aClosure);
MutexAutoLock lock(blocklist->mMutex);
MOZ_LOG(gCertBlockPRLog, LogLevel::Warning,

View File

@@ -135,10 +135,9 @@ EvalChain(const UniqueCERTCertList& certList,
Comparator for the is public key pinned host.
*/
static int
TransportSecurityPreloadCompare(const void *key, const void *entry) {
const char *keyStr = reinterpret_cast<const char *>(key);
const TransportSecurityPreload *preloadEntry =
reinterpret_cast<const TransportSecurityPreload *>(entry);
TransportSecurityPreloadCompare(const void* key, const void* entry) {
auto keyStr = static_cast<const char*>(key);
auto preloadEntry = static_cast<const TransportSecurityPreload*>(entry);
return strcmp(keyStr, preloadEntry->mHost);
}

View File

@@ -58,9 +58,9 @@ RootCABinNumber(const SECItem* cert)
digest.get().data[0], digest.get().data[1], digest.get().data[2], digest.get().data[3]));
if (mozilla::BinarySearchIf(ROOT_TABLE, 0, ArrayLength(ROOT_TABLE),
BinaryHashSearchArrayComparator(
reinterpret_cast<const uint8_t*>(digest.get().data), digest.get().len),
&idx)) {
BinaryHashSearchArrayComparator(static_cast<uint8_t*>(digest.get().data),
digest.get().len),
&idx)) {
MOZ_LOG(gPublicKeyPinningTelemetryLog, LogLevel::Debug,
("pkpinTelem: Telemetry index was %lu, bin is %d\n",

View File

@@ -182,10 +182,10 @@ nsCertTree::FreeCertArray()
mDispInfo.Clear();
}
CompareCacheHashEntry *
nsCertTree::getCacheEntry(void *cache, void *aCert)
CompareCacheHashEntry*
nsCertTree::getCacheEntry(void* cache, void* aCert)
{
PLDHashTable &aCompareCache = *reinterpret_cast<PLDHashTable*>(cache);
PLDHashTable& aCompareCache = *static_cast<PLDHashTable*>(cache);
auto entryPtr = static_cast<CompareCacheHashEntryPtr*>
(aCompareCache.Add(aCert, fallible));
return entryPtr ? entryPtr->entry : nullptr;

View File

@@ -154,7 +154,7 @@ VerifyCMSDetachedSignatureIncludingCertificate(
// signedData is non-owning
NSSCMSSignedData* signedData =
reinterpret_cast<NSSCMSSignedData*>(NSS_CMSContentInfo_GetContent(cinfo));
static_cast<NSSCMSSignedData*>(NSS_CMSContentInfo_GetContent(cinfo));
if (!signedData) {
return NS_ERROR_CMS_VERIFY_NO_CONTENT_INFO;
}
@@ -242,7 +242,7 @@ VerifyCertificate(CERTCertificate* cert, void* voidContext, void* pinArg)
}
VerifyCertificateContext* context =
reinterpret_cast<VerifyCertificateContext*>(voidContext);
static_cast<VerifyCertificateContext*>(voidContext);
nsCOMPtr<nsIX509Cert> xpcomCert(nsNSSCertificate::Create(cert));
if (!xpcomCert) {

View File

@@ -451,7 +451,7 @@ ParseType2Msg(const void *inBuf, uint32_t inLen, Type2Msg *msg)
if (inLen < NTLM_TYPE2_HEADER_LEN)
return NS_ERROR_UNEXPECTED;
const uint8_t *cursor = reinterpret_cast<const uint8_t*>(inBuf);
auto cursor = static_cast<const uint8_t*>(inBuf);
// verify NTLMSSP signature
if (memcmp(cursor, NTLM_SIGNATURE, sizeof(NTLM_SIGNATURE)) != 0)
@@ -478,7 +478,7 @@ ParseType2Msg(const void *inBuf, uint32_t inLen, Type2Msg *msg)
// integer overflow checking.
if (MOZ_LIKELY(targetEnd.isValid() && targetEnd.value() <= inLen)) {
msg->targetLen = targetLen;
msg->target = reinterpret_cast<const uint8_t*>(inBuf) + offset;
msg->target = static_cast<const uint8_t*>(inBuf) + offset;
} else {
// Do not error out, for (conservative) backward compatibility.
msg->targetLen = 0;
@@ -514,7 +514,7 @@ ParseType2Msg(const void *inBuf, uint32_t inLen, Type2Msg *msg)
// integer overflow checking.
if (MOZ_LIKELY(targetInfoEnd.isValid() && targetInfoEnd.value() <= inLen)) {
msg->targetInfoLen = targetInfoLen;
msg->targetInfo = reinterpret_cast<const uint8_t*>(inBuf) + offset;
msg->targetInfo = static_cast<const uint8_t*>(inBuf) + offset;
} else {
NS_ERROR("failed to get NTLMv2 target info");
return NS_ERROR_UNEXPECTED;
@@ -572,7 +572,8 @@ GenerateType3Msg(const nsString &domain,
ucsDomainBuf = domain;
domainPtr = ucsDomainBuf.get();
domainLen = ucsDomainBuf.Length() * 2;
WriteUnicodeLE((void *) domainPtr, reinterpret_cast<const char16_t*> (domainPtr),
WriteUnicodeLE(const_cast<void*>(domainPtr),
static_cast<const char16_t*>(domainPtr),
ucsDomainBuf.Length());
#else
domainPtr = domain.get();
@@ -595,7 +596,8 @@ GenerateType3Msg(const nsString &domain,
ucsUserBuf = username;
userPtr = ucsUserBuf.get();
userLen = ucsUserBuf.Length() * 2;
WriteUnicodeLE((void *) userPtr, reinterpret_cast<const char16_t*> (userPtr),
WriteUnicodeLE(const_cast<void*>(userPtr),
static_cast<const char16_t*>(userPtr),
ucsUserBuf.Length());
#else
userPtr = username.get();
@@ -625,7 +627,8 @@ GenerateType3Msg(const nsString &domain,
hostPtr = ucsHostBuf.get();
hostLen = ucsHostBuf.Length() * 2;
#ifdef IS_BIG_ENDIAN
WriteUnicodeLE((void *) hostPtr, reinterpret_cast<const char16_t*> (hostPtr),
WriteUnicodeLE(const_cast<void*>(hostPtr),
static_cast<const char16_t*>(hostPtr),
ucsHostBuf.Length());
#endif
}
@@ -671,14 +674,16 @@ GenerateType3Msg(const nsString &domain,
userUpperPtr = ucsUserUpperBuf.get();
userUpperLen = ucsUserUpperBuf.Length() * 2;
#ifdef IS_BIG_ENDIAN
WriteUnicodeLE((void *) userUpperPtr, reinterpret_cast<const char16_t*> (userUpperPtr),
WriteUnicodeLE(const_cast<void*>(userUpperPtr),
static_cast<const char16_t*>(userUpperPtr),
ucsUserUpperBuf.Length());
#endif
ToUpperCase(domain, ucsDomainUpperBuf);
domainUpperPtr = ucsDomainUpperBuf.get();
domainUpperLen = ucsDomainUpperBuf.Length() * 2;
#ifdef IS_BIG_ENDIAN
WriteUnicodeLE((void *) domainUpperPtr, reinterpret_cast<const char16_t*> (domainUpperPtr),
WriteUnicodeLE(const_cast<void*>(domainUpperPtr),
static_cast<const char16_t*>(domainUpperPtr),
ucsDomainUpperBuf.Length());
#endif
@@ -712,11 +717,12 @@ GenerateType3Msg(const nsString &domain,
if (NS_FAILED(rv)) {
return rv;
}
rv = hasher->Update(reinterpret_cast<const uint8_t*> (userUpperPtr), userUpperLen);
rv = hasher->Update(static_cast<const uint8_t*>(userUpperPtr), userUpperLen);
if (NS_FAILED(rv)) {
return rv;
}
rv = hasher->Update(reinterpret_cast<const uint8_t*> (domainUpperPtr), domainUpperLen);
rv = hasher->Update(static_cast<const uint8_t*>(domainUpperPtr),
domainUpperLen);
if (NS_FAILED(rv)) {
return rv;
}
@@ -892,7 +898,7 @@ GenerateType3Msg(const nsString &domain,
return NS_ERROR_UNEXPECTED;
}
cursor = WriteSecBuf(cursor, LM_RESP_LEN, offset.value());
memcpy((uint8_t *) *outBuf + offset.value(), lmResp, LM_RESP_LEN);
memcpy(static_cast<uint8_t*>(*outBuf) + offset.value(), lmResp, LM_RESP_LEN);
// 20 : NTLM or NTLMv2 response sec buf
offset += LM_RESP_LEN;
@@ -902,26 +908,30 @@ GenerateType3Msg(const nsString &domain,
}
cursor = WriteSecBuf(cursor, ntlmRespLen.value(), offset.value());
if (ntlmv2) {
memcpy(reinterpret_cast<uint8_t*> (*outBuf) + offset.value(), ntlmv2Resp, NTLMv2_RESP_LEN);
memcpy(static_cast<uint8_t*>(*outBuf) + offset.value(), ntlmv2Resp,
NTLMv2_RESP_LEN);
offset += NTLMv2_RESP_LEN;
if (!offset.isValid()) {
NS_ERROR("failed preparing to write NTLM response: integer overflow?!?");
return NS_ERROR_UNEXPECTED;
}
memcpy(reinterpret_cast<uint8_t*> (*outBuf) + offset.value(), ntlmv2_blob1, NTLMv2_BLOB1_LEN);
memcpy(static_cast<uint8_t*>(*outBuf) + offset.value(), ntlmv2_blob1,
NTLMv2_BLOB1_LEN);
offset += NTLMv2_BLOB1_LEN;
if (!offset.isValid()) {
NS_ERROR("failed preparing to write NTLM response: integer overflow?!?");
return NS_ERROR_UNEXPECTED;
}
memcpy(reinterpret_cast<uint8_t*> (*outBuf) + offset.value(), msg.targetInfo, msg.targetInfoLen);
memcpy(static_cast<uint8_t*>(*outBuf) + offset.value(), msg.targetInfo,
msg.targetInfoLen);
} else {
memcpy(reinterpret_cast<uint8_t*> (*outBuf) + offset.value(), ntlmResp, NTLM_RESP_LEN);
memcpy(static_cast<uint8_t*>(*outBuf) + offset.value(), ntlmResp,
NTLM_RESP_LEN);
}
// 28 : domain name sec buf
offset = NTLM_TYPE3_HEADER_LEN;
cursor = WriteSecBuf(cursor, domainLen, offset.value());
memcpy((uint8_t *) *outBuf + offset.value(), domainPtr, domainLen);
memcpy(static_cast<uint8_t*>(*outBuf) + offset.value(), domainPtr, domainLen);
// 36 : user name sec buf
offset += domainLen;
@@ -930,7 +940,7 @@ GenerateType3Msg(const nsString &domain,
return NS_ERROR_UNEXPECTED;
}
cursor = WriteSecBuf(cursor, userLen, offset.value());
memcpy(reinterpret_cast<uint8_t*> (*outBuf) + offset.value(), userPtr, userLen);
memcpy(static_cast<uint8_t*>(*outBuf) + offset.value(), userPtr, userLen);
// 44 : workstation (host) name sec buf
offset += userLen;
@@ -939,7 +949,7 @@ GenerateType3Msg(const nsString &domain,
return NS_ERROR_UNEXPECTED;
}
cursor = WriteSecBuf(cursor, hostLen, offset.value());
memcpy(reinterpret_cast<uint8_t*> (*outBuf) + offset.value(), hostPtr, hostLen);
memcpy(static_cast<uint8_t*>(*outBuf) + offset.value(), hostPtr, hostLen);
// 52 : session key sec buf (not used)
cursor = WriteSecBuf(cursor, 0, 0);

View File

@@ -513,9 +513,9 @@ nsPKCS12Blob::inputToDecoder(SEC_PKCS12DecoderContext *dcx, nsIFile *file)
SECStatus
nsPKCS12Blob::digest_open(void *arg, PRBool reading)
{
nsPKCS12Blob *cx = reinterpret_cast<nsPKCS12Blob *>(arg);
auto cx = static_cast<nsPKCS12Blob*>(arg);
NS_ENSURE_TRUE(cx, SECFailure);
if (reading) {
NS_ENSURE_TRUE(cx->mDigest, SECFailure);
@@ -548,17 +548,17 @@ nsPKCS12Blob::digest_open(void *arg, PRBool reading)
SECStatus
nsPKCS12Blob::digest_close(void *arg, PRBool remove_it)
{
nsPKCS12Blob *cx = reinterpret_cast<nsPKCS12Blob *>(arg);
auto cx = static_cast<nsPKCS12Blob*>(arg);
NS_ENSURE_TRUE(cx, SECFailure);
delete cx->mDigestIterator;
cx->mDigestIterator = nullptr;
if (remove_it) {
if (remove_it) {
delete cx->mDigest;
cx->mDigest = nullptr;
}
return SECSuccess;
}
@@ -567,7 +567,7 @@ nsPKCS12Blob::digest_close(void *arg, PRBool remove_it)
int
nsPKCS12Blob::digest_read(void *arg, unsigned char *buf, unsigned long len)
{
nsPKCS12Blob *cx = reinterpret_cast<nsPKCS12Blob *>(arg);
auto cx = static_cast<nsPKCS12Blob*>(arg);
NS_ENSURE_TRUE(cx, SECFailure);
NS_ENSURE_TRUE(cx->mDigest, SECFailure);
@@ -575,13 +575,13 @@ nsPKCS12Blob::digest_read(void *arg, unsigned char *buf, unsigned long len)
NS_ENSURE_TRUE(cx->mDigestIterator, SECFailure);
unsigned long available = cx->mDigestIterator->size_forward();
if (len > available)
len = available;
memcpy(buf, cx->mDigestIterator->get(), len);
cx->mDigestIterator->advance(len);
return len;
}
@@ -590,16 +590,16 @@ nsPKCS12Blob::digest_read(void *arg, unsigned char *buf, unsigned long len)
int
nsPKCS12Blob::digest_write(void *arg, unsigned char *buf, unsigned long len)
{
nsPKCS12Blob *cx = reinterpret_cast<nsPKCS12Blob *>(arg);
auto cx = static_cast<nsPKCS12Blob*>(arg);
NS_ENSURE_TRUE(cx, SECFailure);
NS_ENSURE_TRUE(cx->mDigest, SECFailure);
// make sure we are in write mode, read iterator has not yet been allocated
NS_ENSURE_FALSE(cx->mDigestIterator, SECFailure);
cx->mDigest->Append(reinterpret_cast<char *>(buf),
static_cast<uint32_t>(len));
return len;
}

View File

@@ -29,7 +29,7 @@ nsRandomGenerator::GenerateRandomBytes(uint32_t aLength,
return NS_ERROR_FAILURE;
}
uint8_t* buf = reinterpret_cast<uint8_t*>(moz_xmalloc(aLength));
auto buf = static_cast<uint8_t*>(moz_xmalloc(aLength));
if (!buf) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@@ -447,7 +447,7 @@ ConfigSecureServerWithNamedCert(PRFileDesc* fd, const char* certName,
certList->arena = arena.release();
// We also have to manually copy the certificates we care about to the
// list, because there aren't any utility functions for that either.
certList->certs = reinterpret_cast<SECItem*>(
certList->certs = static_cast<SECItem*>(
PORT_ArenaAlloc(certList->arena, 2 * sizeof(SECItem)));
if (SECITEM_CopyItem(certList->arena, certList->certs, &cert->derCert)
!= SECSuccess) {