From 4f3a7ca850812d7c4dfa4158beaa43cc57d46903 Mon Sep 17 00:00:00 2001 From: "cbiesinger%web.de" Date: Thu, 25 Dec 2003 22:05:01 +0000 Subject: [PATCH] Bug 183871 Crash on "Show hidden files and directories" [@ nsFileView::SetDirectory(nsIFile*) ] fix: don't let files be initialized with relative paths. also fix the directory service to not do that. r=dougt sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@150734 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/io/nsDirectoryService.cpp | 38 ++++++++++++------------- mozilla/xpcom/io/nsLocalFileUnix.cpp | 3 ++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/mozilla/xpcom/io/nsDirectoryService.cpp b/mozilla/xpcom/io/nsDirectoryService.cpp index 973f760fe55..46307e57da6 100644 --- a/mozilla/xpcom/io/nsDirectoryService.cpp +++ b/mozilla/xpcom/io/nsDirectoryService.cpp @@ -252,31 +252,29 @@ nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) if (moz5) { - localFile->InitWithNativePath(nsDependentCString(moz5)); - localFile->Normalize(); - *aFile = localFile; - return NS_OK; - } - else - { -#if defined(DEBUG) - static PRBool firstWarning = PR_TRUE; - - if(firstWarning) { - // Warn that MOZILLA_FIVE_HOME not set, once. - printf("Warning: MOZILLA_FIVE_HOME not set.\n"); - firstWarning = PR_FALSE; - } -#endif /* DEBUG */ - - // Fall back to current directory. - if (getcwd(buf, sizeof(buf))) - { + if (realpath(moz5, buf)) { localFile->InitWithNativePath(nsDependentCString(buf)); *aFile = localFile; return NS_OK; } } +#if defined(DEBUG) + static PRBool firstWarning = PR_TRUE; + + if(!moz5 && firstWarning) { + // Warn that MOZILLA_FIVE_HOME not set, once. + printf("Warning: MOZILLA_FIVE_HOME not set.\n"); + firstWarning = PR_FALSE; + } +#endif /* DEBUG */ + + // Fall back to current directory. + if (getcwd(buf, sizeof(buf))) + { + localFile->InitWithNativePath(nsDependentCString(buf)); + *aFile = localFile; + return NS_OK; + } #elif defined(XP_OS2) PPIB ppib; diff --git a/mozilla/xpcom/io/nsLocalFileUnix.cpp b/mozilla/xpcom/io/nsLocalFileUnix.cpp index 281113e8292..de6a41b4c4c 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnix.cpp @@ -270,6 +270,9 @@ nsLocalFile::InitWithNativePath(const nsACString &filePath) } mPath = homePath + Substring(filePath, 1, filePath.Length() - 1); + } else if (filePath.IsEmpty() || filePath.First() != '/') { + NS_ERROR("Relative paths not allowed"); + return NS_ERROR_FILE_UNRECOGNIZED_PATH; } else { mPath = filePath; }