зеркало из https://github.com/mozilla/pjs.git
Bug 283563 OOM crash [@ GetSlotWithMechanism][@ nsKeygenFormProcessor::GetPublicKey]
patch by b.jacques@planet.nl r=kaie sr=darin a=bsmedberg
This commit is contained in:
Родитель
8dd86f5c13
Коммит
d8c194a5b7
|
@ -310,12 +310,24 @@ GetSlotWithMechanism(PRUint32 aMechanism,
|
||||||
|
|
||||||
// Allocate the slot name buffer //
|
// Allocate the slot name buffer //
|
||||||
tokenNameList = NS_STATIC_CAST(PRUnichar**, nsMemory::Alloc(sizeof(PRUnichar *) * numSlots));
|
tokenNameList = NS_STATIC_CAST(PRUnichar**, nsMemory::Alloc(sizeof(PRUnichar *) * numSlots));
|
||||||
|
if (!tokenNameList) {
|
||||||
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
goto loser;
|
||||||
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
slotElement = PK11_GetFirstSafe(slotList);
|
slotElement = PK11_GetFirstSafe(slotList);
|
||||||
while (slotElement) {
|
while (slotElement) {
|
||||||
tokenNameList[i] = ToNewUnicode(NS_ConvertUTF8toUCS2(PK11_GetTokenName(slotElement->slot)));
|
tokenNameList[i] = UTF8ToNewUnicode(nsDependentCString(PK11_GetTokenName(slotElement->slot)));
|
||||||
slotElement = PK11_GetNextSafe(slotList, slotElement, PR_FALSE);
|
slotElement = PK11_GetNextSafe(slotList, slotElement, PR_FALSE);
|
||||||
i++;
|
if (tokenNameList[i])
|
||||||
|
i++;
|
||||||
|
else {
|
||||||
|
// OOM. adjust numSlots so we don't free unallocated memory.
|
||||||
|
numSlots = i;
|
||||||
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
goto loser;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Throw up the token list dialog and get back the token */
|
/* Throw up the token list dialog and get back the token */
|
||||||
|
@ -327,7 +339,10 @@ GetSlotWithMechanism(PRUint32 aMechanism,
|
||||||
|
|
||||||
{
|
{
|
||||||
nsPSMUITracker tracker;
|
nsPSMUITracker tracker;
|
||||||
if (tracker.isUIForbidden()) {
|
if (!tokenNameList || !*tokenNameList) {
|
||||||
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
else if (tracker.isUIForbidden()) {
|
||||||
rv = NS_ERROR_NOT_AVAILABLE;
|
rv = NS_ERROR_NOT_AVAILABLE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -362,7 +377,7 @@ loser:
|
||||||
PK11_FreeSlotList(slotList);
|
PK11_FreeSlotList(slotList);
|
||||||
}
|
}
|
||||||
if (tokenNameList) {
|
if (tokenNameList) {
|
||||||
nsMemory::Free(tokenNameList);
|
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(numSlots, tokenNameList);
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
@ -394,6 +409,7 @@ nsKeygenFormProcessor::GetPublicKey(nsAString& aValue, nsAString& aChallenge,
|
||||||
SECItem pkacItem;
|
SECItem pkacItem;
|
||||||
SECItem signedItem;
|
SECItem signedItem;
|
||||||
CERTPublicKeyAndChallenge pkac;
|
CERTPublicKeyAndChallenge pkac;
|
||||||
|
pkac.challenge.data = nsnull;
|
||||||
SECKeySizeChoiceInfo *choice = SECKeySizeChoiceList;
|
SECKeySizeChoiceInfo *choice = SECKeySizeChoiceList;
|
||||||
nsIGeneratingKeypairInfoDialogs * dialogs;
|
nsIGeneratingKeypairInfoDialogs * dialogs;
|
||||||
nsKeygenThread *KeygenRunnable = 0;
|
nsKeygenThread *KeygenRunnable = 0;
|
||||||
|
@ -423,11 +439,16 @@ nsKeygenFormProcessor::GetPublicKey(nsAString& aValue, nsAString& aChallenge,
|
||||||
} else if (aKeyType.LowerCaseEqualsLiteral("dsa")) {
|
} else if (aKeyType.LowerCaseEqualsLiteral("dsa")) {
|
||||||
char * end;
|
char * end;
|
||||||
pqgString = ToNewCString(aPqg);
|
pqgString = ToNewCString(aPqg);
|
||||||
|
if (!pqgString) {
|
||||||
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
goto loser;
|
||||||
|
}
|
||||||
|
|
||||||
type = dsaKey;
|
type = dsaKey;
|
||||||
keyGenMechanism = CKM_DSA_KEY_PAIR_GEN;
|
keyGenMechanism = CKM_DSA_KEY_PAIR_GEN;
|
||||||
if (strcmp(pqgString, "null") == 0)
|
if (strcmp(pqgString, "null") == 0)
|
||||||
goto loser;
|
goto loser;
|
||||||
str = pqgString;
|
str = pqgString;
|
||||||
do {
|
do {
|
||||||
end = strchr(str, ',');
|
end = strchr(str, ',');
|
||||||
if (end != nsnull)
|
if (end != nsnull)
|
||||||
|
@ -540,8 +561,12 @@ found_match:
|
||||||
* set up the PublicKeyAndChallenge data structure, then DER encode it
|
* set up the PublicKeyAndChallenge data structure, then DER encode it
|
||||||
*/
|
*/
|
||||||
pkac.spki = spkiItem;
|
pkac.spki = spkiItem;
|
||||||
pkac.challenge.len = aChallenge.Length();
|
pkac.challenge.len = aChallenge.Length();
|
||||||
pkac.challenge.data = (unsigned char *)ToNewCString(aChallenge);
|
pkac.challenge.data = (unsigned char *)ToNewCString(aChallenge);
|
||||||
|
if (!pkac.challenge.data) {
|
||||||
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
goto loser;
|
||||||
|
}
|
||||||
|
|
||||||
sec_rv = DER_Encode(arena, &pkacItem, CERTPublicKeyAndChallengeTemplate, &pkac);
|
sec_rv = DER_Encode(arena, &pkacItem, CERTPublicKeyAndChallengeTemplate, &pkac);
|
||||||
if ( sec_rv != SECSuccess ) {
|
if ( sec_rv != SECSuccess ) {
|
||||||
|
@ -561,6 +586,10 @@ found_match:
|
||||||
* Convert the signed public key and challenge into base64/ascii.
|
* Convert the signed public key and challenge into base64/ascii.
|
||||||
*/
|
*/
|
||||||
keystring = BTOA_DataToAscii(signedItem.data, signedItem.len);
|
keystring = BTOA_DataToAscii(signedItem.data, signedItem.len);
|
||||||
|
if (!keystring) {
|
||||||
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
goto loser;
|
||||||
|
}
|
||||||
|
|
||||||
CopyASCIItoUTF16(keystring, aOutPublicKey);
|
CopyASCIItoUTF16(keystring, aOutPublicKey);
|
||||||
nsCRT::free(keystring);
|
nsCRT::free(keystring);
|
||||||
|
@ -593,6 +622,12 @@ loser:
|
||||||
if (KeygenRunnable) {
|
if (KeygenRunnable) {
|
||||||
NS_RELEASE(KeygenRunnable);
|
NS_RELEASE(KeygenRunnable);
|
||||||
}
|
}
|
||||||
|
if (pqgString) {
|
||||||
|
nsMemory::Free(pqgString);
|
||||||
|
}
|
||||||
|
if (pkac.challenge.data) {
|
||||||
|
nsMemory::Free(pkac.challenge.data);
|
||||||
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче