From d7ba6ae5657d34c22da317ebb09cccf17c5d0bb8 Mon Sep 17 00:00:00 2001 From: "kaie%netscape.com" Date: Tue, 4 Feb 2003 01:37:23 +0000 Subject: [PATCH] b=191301 Crash if I cancel "Choose token" dialog on Cert import r=javi sr=darin a=dbaron git-svn-id: svn://10.0.0.236/trunk@137345 18797224-902f-48f8-a5cc-f745e15eee43 --- .../security/manager/ssl/src/nsPKCS12Blob.cpp | 31 ++++++++++++------- .../security/manager/ssl/src/nsPKCS12Blob.h | 4 +-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp b/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp index 365ff42b811..a0453595c84 100644 --- a/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp +++ b/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp @@ -31,7 +31,7 @@ * may use your version of this file under either the MPL or the * GPL. * - * $Id: nsPKCS12Blob.cpp,v 1.34 2003-01-18 14:02:59 kaie%netscape.com Exp $ + * $Id: nsPKCS12Blob.cpp,v 1.35 2003-02-04 01:37:22 kaie%netscape.com Exp $ */ #include "prmem.h" @@ -99,15 +99,16 @@ nsPKCS12Blob::~nsPKCS12Blob() // nsPKCS12Blob::SetToken // // Set the token to use for import/export -void +nsresult nsPKCS12Blob::SetToken(nsIPK11Token *token) { nsNSSShutDownPreventionLock locker; + nsresult rv = NS_OK; if (token) { mToken = token; } else { PK11SlotInfo *slot; - nsresult rv = GetSlotWithMechanism(CKM_RSA_PKCS, mUIContext,&slot); + rv = GetSlotWithMechanism(CKM_RSA_PKCS, mUIContext,&slot); if (NS_FAILED(rv)) { mToken = 0; } else { @@ -116,6 +117,7 @@ nsPKCS12Blob::SetToken(nsIPK11Token *token) } } mTokenSet = PR_TRUE; + return rv; } // nsPKCS12Blob::ImportFromFile @@ -126,16 +128,23 @@ nsresult nsPKCS12Blob::ImportFromFile(nsILocalFile *file) { nsNSSShutDownPreventionLock locker; - nsresult rv; + nsresult rv = NS_OK; - if (!mToken && !mTokenSet) { - SetToken(NULL); // Ask the user to pick a slot - } else if (!mToken && mTokenSet) { - // Someone tried setting the token before, but that failed. - // Probably because the user canceled. - handleError(PIP_PKCS12_USER_CANCELED); - return NS_OK; + if (!mToken) { + if (!mTokenSet) { + rv = SetToken(NULL); // Ask the user to pick a slot + if (NS_FAILED(rv)) { + handleError(PIP_PKCS12_USER_CANCELED); + return rv; + } + } } + + if (!mToken) { + handleError(PIP_PKCS12_RESTORE_FAILED); + return NS_ERROR_NOT_AVAILABLE; + } + // init slot rv = mToken->Login(PR_TRUE); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/security/manager/ssl/src/nsPKCS12Blob.h b/mozilla/security/manager/ssl/src/nsPKCS12Blob.h index cb720681f52..28ef7a2b92a 100644 --- a/mozilla/security/manager/ssl/src/nsPKCS12Blob.h +++ b/mozilla/security/manager/ssl/src/nsPKCS12Blob.h @@ -31,7 +31,7 @@ * may use your version of this file under either the MPL or the * GPL. * - * $Id: nsPKCS12Blob.h,v 1.10 2002-10-14 14:48:57 kaie%netscape.com Exp $ + * $Id: nsPKCS12Blob.h,v 1.11 2003-02-04 01:37:23 kaie%netscape.com Exp $ */ #ifndef _NS_PKCS12BLOB_H_ @@ -65,7 +65,7 @@ public: virtual ~nsPKCS12Blob(); // Set the token to use (default is internal) - void SetToken(nsIPK11Token *token); + nsresult SetToken(nsIPK11Token *token); // PKCS#12 Import nsresult ImportFromFile(nsILocalFile *file);