From edc9692ee05e1dbdca8ef388f564ee3934fc8ead Mon Sep 17 00:00:00 2001 From: "timeless%mozdev.org" Date: Fri, 14 Mar 2003 04:03:08 +0000 Subject: [PATCH] Bug 196299 nsSafeSaveFile::CreateBackup dereferences a NULL nsCOMPtr with operator->() r=ccarlen sr=dveditz git-svn-id: svn://10.0.0.236/trunk@139428 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/libpref/src/nsSafeSaveFile.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mozilla/modules/libpref/src/nsSafeSaveFile.cpp b/mozilla/modules/libpref/src/nsSafeSaveFile.cpp index 1b7b878478f..93fe38cf14a 100644 --- a/mozilla/modules/libpref/src/nsSafeSaveFile.cpp +++ b/mozilla/modules/libpref/src/nsSafeSaveFile.cpp @@ -48,9 +48,9 @@ nsSafeSaveFile::nsSafeSaveFile(nsIFile *aTargetFile, PRInt32 aNumBackupCopies) nsresult rv; // determine if the target file currently exists - aTargetFile->Exists(&mTargetFileExists); - // if the target file doesn't exist this object does nothing + if (NS_FAILED(aTargetFile->Exists(&mTargetFileExists))) + mTargetFileExists = PR_FALSE; if (!mTargetFileExists) return; @@ -84,7 +84,7 @@ nsSafeSaveFile::nsSafeSaveFile(nsIFile *aTargetFile, PRInt32 aNumBackupCopies) nsSafeSaveFile::~nsSafeSaveFile(void) { // if the target file didn't exist nothing was backed up - if (mTargetFileExists) { + if (mTargetFileExists && mBackupFile) { // if no backups desired, remove the backup file if (mBackupCount == 0) { mBackupFile->Remove(PR_FALSE); @@ -103,8 +103,7 @@ nsresult nsSafeSaveFile::CreateBackup(PurgeBackupType aPurgeType) return NS_OK; // if a backup file currently exists... do the right thing - mBackupFile->Exists(&bExists); - if (bExists) { + if (mBackupFile && NS_SUCCEEDED(mBackupFile->Exists(&bExists)) && bExists) { rv = ManageRedundantBackups(); if (NS_FAILED(rv)) return rv; @@ -148,6 +147,9 @@ nsresult nsSafeSaveFile::RestoreFromBackup(void) if (!mTargetFileExists) return NS_ERROR_FILE_NOT_FOUND; + if (!mBackupFile) + return NS_ERROR_NOT_INITIALIZED; + rv = mTargetFile->GetNativeLeafName(fileName); if (NS_FAILED(rv)) // yikes! out of memory return rv; @@ -214,6 +216,9 @@ nsresult nsSafeSaveFile::PurgeOldestRedundantBackup(void) nsCAutoString fileName; nsresult rv; + if (!mBackupFile) + return NS_ERROR_NULL_POINTER; + rv = mBackupFile->Clone(getter_AddRefs(backupFile)); if (NS_FAILED(rv)) // yikes! out of memory, probably best to not continue return rv;