Bug 644070 - nsNSSCertificate::defaultServerNickname leaks in case of server name conflict; r=mayhemer

This commit is contained in:
Ehsan Akhgari 2011-03-27 15:09:32 -04:00
parent b5f305985c
commit ab717a320a
3 changed files with 16 additions and 10 deletions

View File

@ -513,21 +513,25 @@ nsCertOverrideService::RememberValidityOverride(const nsACString & aHostName, PR
CERTCertificateCleaner nsscertCleaner(nsscert);
nsCAutoString nickname;
nickname = nsNSSCertificate::defaultServerNickname(nsscert);
if (!aTemporary && !nickname.IsEmpty())
char* nickname = nsNSSCertificate::defaultServerNickname(nsscert);
if (!aTemporary && nickname && *nickname)
{
PK11SlotInfo *slot = PK11_GetInternalKeySlot();
if (!slot)
if (!slot) {
PR_Free(nickname);
return NS_ERROR_FAILURE;
}
SECStatus srv = PK11_ImportCert(slot, nsscert, CK_INVALID_HANDLE,
const_cast<char*>(nickname.get()), PR_FALSE);
nickname, PR_FALSE);
PK11_FreeSlot(slot);
if (srv != SECSuccess)
if (srv != SECSuccess) {
PR_Free(nickname);
return NS_ERROR_FAILURE;
}
}
PR_FREEIF(nickname);
nsCAutoString fpStr;
nsresult rv = GetCertFingerprintByOidTag(nsscert,

View File

@ -1099,16 +1099,16 @@ SECStatus PR_CALLBACK AuthCertificateCallback(void* client_data, PRFileDesc* fd,
}
// We have found a signer cert that we want to remember.
nsCAutoString nickname;
nickname = nsNSSCertificate::defaultServerNickname(node->cert);
if (!nickname.IsEmpty()) {
char* nickname = nsNSSCertificate::defaultServerNickname(node->cert);
if (nickname && *nickname) {
PK11SlotInfo *slot = PK11_GetInternalKeySlot();
if (slot) {
PK11_ImportCert(slot, node->cert, CK_INVALID_HANDLE,
const_cast<char*>(nickname.get()), PR_FALSE);
nickname, PR_FALSE);
PK11_FreeSlot(slot);
}
}
PR_FREEIF(nickname);
}
CERT_DestroyCertList(certList);

View File

@ -85,6 +85,8 @@ public:
static nsNSSCertificate* Create(CERTCertificate *cert = nsnull);
static nsNSSCertificate* ConstructFromDER(char *certDER, int derLen);
// It is the responsibility of the caller of this method to free the returned
// string using PR_Free.
static char* defaultServerNickname(CERTCertificate* cert);
private: