Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1376520 - some static analysis (infer) fixes, r=ttaubert
Differential Revision: https://nss-review.dev.mozaws.net/D354

--HG--
extra : rebase_source : ba7b5a25ed43d5544b1bb6dd745f59fa3ce2a523
extra : amend_source : d1c894a2450751028ddb15c318233efb6a528444
  • Loading branch information
franziskuskiefer committed Jun 27, 2017
1 parent bfc2ca5 commit a11cb93
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 11 deletions.
3 changes: 3 additions & 0 deletions cmd/symkeyutil/symkeyutil.c
Expand Up @@ -233,6 +233,9 @@ BufToHex(SECItem *outbuf)
unsigned int i;

string = PORT_Alloc(len);
if (!string) {
return NULL;
}

ptr = string;
for (i = 0; i < outbuf->len; i++) {
Expand Down
4 changes: 4 additions & 0 deletions cpputil/dummy_io.cc
Expand Up @@ -19,6 +19,10 @@ extern const struct PRIOMethods DummyMethodsForward;
ScopedPRFileDesc DummyIOLayerMethods::CreateFD(PRDescIdentity id,
DummyIOLayerMethods *methods) {
ScopedPRFileDesc fd(PR_CreateIOLayerStub(id, &DummyMethodsForward));
assert(fd);
if (!fd) {
return nullptr;
}
fd->secret = reinterpret_cast<PRFilePrivate *>(methods);
return fd;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/certdb/certv3.c
Expand Up @@ -213,7 +213,7 @@ CERT_CheckCertUsage(CERTCertificate *cert, unsigned char usage)
if (rv == SECFailure) {
rv = (PORT_GetError() == SEC_ERROR_EXTENSION_NOT_FOUND) ? SECSuccess
: SECFailure;
} else if (!(keyUsage.data[0] & usage)) {
} else if (!keyUsage.data || !(keyUsage.data[0] & usage)) {
PORT_SetError(SEC_ERROR_CERT_USAGES_INVALID);
rv = SECFailure;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/freebl/rsa.c
Expand Up @@ -321,7 +321,6 @@ RSA_NewKey(int keySizeInBits, SECItem *publicExponent)
kiter = 0;
max_attempts = 5 * (keySizeInBits / 2); /* FIPS 186-4 B.3.3 steps 4.7 and 5.8 */
do {
prerr = 0;
PORT_SetError(0);
CHECK_SEC_OK(generate_prime(&p, primeLen));
CHECK_SEC_OK(generate_prime(&q, primeLen));
Expand All @@ -348,8 +347,7 @@ RSA_NewKey(int keySizeInBits, SECItem *publicExponent)
kiter++;
/* loop until have primes */
} while (prerr == SEC_ERROR_NEED_RANDOM && kiter < max_attempts);
if (prerr)
goto cleanup;

cleanup:
mp_clear(&p);
mp_clear(&q);
Expand Down
13 changes: 10 additions & 3 deletions lib/freebl/rsapkcs.c
Expand Up @@ -290,10 +290,12 @@ MGF1(HASH_HashType hashAlg,
const SECHashObject *hash;
void *hashContext;
unsigned char C[4];
SECStatus rv = SECSuccess;

hash = HASH_GetRawHashObject(hashAlg);
if (hash == NULL)
if (hash == NULL) {
return SECFailure;
}

hashContext = (*hash->create)();
rounds = (maskLen + hash->length - 1) / hash->length;
Expand All @@ -314,14 +316,19 @@ MGF1(HASH_HashType hashAlg,
(*hash->end)(hashContext, tempHash, &digestLen, hash->length);
} else { /* we're in the last round and need to cut the hash */
temp = (unsigned char *)PORT_Alloc(hash->length);
if (!temp) {
rv = SECFailure;
goto done;
}
(*hash->end)(hashContext, temp, &digestLen, hash->length);
PORT_Memcpy(tempHash, temp, maskLen - counter * hash->length);
PORT_Free(temp);
}
}
(*hash->destroy)(hashContext, PR_TRUE);

return SECSuccess;
done:
(*hash->destroy)(hashContext, PR_TRUE);
return rv;
}

/* XXX Doesn't set error code */
Expand Down
8 changes: 5 additions & 3 deletions lib/pk11wrap/pk11auth.c
Expand Up @@ -704,9 +704,11 @@ PRBool
PK11_NeedPWInit()
{
PK11SlotInfo *slot = PK11_GetInternalKeySlot();
PRBool ret = PK11_NeedPWInitForSlot(slot);

PK11_FreeSlot(slot);
PRBool ret = PR_FALSE;
if (slot) {
ret = PK11_NeedPWInitForSlot(slot);
PK11_FreeSlot(slot);
}
return ret;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/pk11wrap/pk11obj.c
Expand Up @@ -2028,6 +2028,9 @@ PK11_FindObjectsFromNickname(char *nickname, PK11SlotInfo **slotptr,
if ((delimit = PORT_Strchr(nickname, ':')) != NULL) {
int len = delimit - nickname;
tokenName = (char *)PORT_Alloc(len + 1);
if (!tokenName) {
return CK_INVALID_HANDLE;
}
PORT_Memcpy(tokenName, nickname, len);
tokenName[len] = 0;

Expand Down
6 changes: 5 additions & 1 deletion lib/pk11wrap/pk11slot.c
Expand Up @@ -2484,7 +2484,11 @@ PK11_RandomUpdate(void *data, size_t bytes)

if (!bestIsInternal) {
/* do internal slot, too. */
slot = PK11_GetInternalSlot(); /* can't fail */
slot = PK11_GetInternalSlot();
PORT_Assert(slot);
if (!slot) {
return SECFailure;
}
status = PK11_SeedRandom(slot, data, bytes);
PK11_FreeSlot(slot);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/util/quickder.c
Expand Up @@ -408,6 +408,10 @@ DecodePointer(void* dest,
{
const SEC_ASN1Template* ptrTemplate =
SEC_ASN1GetSubtemplate(templateEntry, dest, PR_FALSE);
if (!ptrTemplate) {
PORT_SetError(SEC_ERROR_INVALID_ARGS);
return SECFailure;
}
void* subdata = PORT_ArenaZAlloc(arena, ptrTemplate->size);
*(void**)((char*)dest + templateEntry->offset) = subdata;
if (subdata) {
Expand Down
3 changes: 3 additions & 0 deletions lib/util/secport.c
Expand Up @@ -699,6 +699,9 @@ NSS_PutEnv(const char *envVarName, const char *envValue)
#endif

encoded = (char *)PORT_ZAlloc(strlen(envVarName) + 2 + strlen(envValue));
if (!encoded) {
return SECFailure;
}
strcpy(encoded, envVarName);
strcat(encoded, "=");
strcat(encoded, envValue);
Expand Down

0 comments on commit a11cb93

Please sign in to comment.