summaryrefslogtreecommitdiffstats
path: root/chrome_frame
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 19:51:55 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 19:51:55 +0000
commit4ece1c45a770b1916f0f3eafd41b591e229dbb09 (patch)
tree74ae27a94cc67da9036cd7e9b9873b5142d32950 /chrome_frame
parent4512cb5735330f497d018191595d9bd5ce902ac2 (diff)
downloadchromium_src-4ece1c45a770b1916f0f3eafd41b591e229dbb09.zip
chromium_src-4ece1c45a770b1916f0f3eafd41b591e229dbb09.tar.gz
chromium_src-4ece1c45a770b1916f0f3eafd41b591e229dbb09.tar.bz2
Fix a ChromeFrame crash which was reported in the crash server in the helper function to return the path
to the IE temporary internet files folder. The crash occurs because of dereferencing a NULL parent IShellFolder interface. Fix is to bail out and use the SHGetFolderPath function if the SHGetFolderLocation and the SHBindToParent APIs fail for some reason. The SHGetFolderPath function has a limit of MAX_PATH characters. Added a unit test for the GetIETemporaryFilesFolder helper function. Fixes bug http://code.google.com/p/chromium/issues/detail?id=40266 Bug=40266 Review URL: http://codereview.chromium.org/1523010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43639 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r--chrome_frame/test/util_unittests.cc5
-rw-r--r--chrome_frame/utils.cc61
2 files changed, 44 insertions, 22 deletions
diff --git a/chrome_frame/test/util_unittests.cc b/chrome_frame/test/util_unittests.cc
index 6e066a1..c589416 100644
--- a/chrome_frame/test/util_unittests.cc
+++ b/chrome_frame/test/util_unittests.cc
@@ -104,3 +104,8 @@ TEST(UtilTests, GuidToString) {
EXPECT_EQ(0, str_guid.compare(compare));
EXPECT_EQ(static_cast<size_t>(lstrlenW(compare)), str_guid.length());
}
+
+TEST(UtilTests, GetTempInternetFiles) {
+ FilePath path = GetIETemporaryFilesFolder();
+ EXPECT_FALSE(path.empty());
+}
diff --git a/chrome_frame/utils.cc b/chrome_frame/utils.cc
index 3065c54..e018568 100644
--- a/chrome_frame/utils.cc
+++ b/chrome_frame/utils.cc
@@ -417,31 +417,48 @@ IEVersion GetIEVersion() {
}
FilePath GetIETemporaryFilesFolder() {
- DCHECK_EQ(BROWSER_IE, GetBrowserType());
-
LPITEMIDLIST tif_pidl = NULL;
HRESULT hr = SHGetFolderLocation(NULL, CSIDL_INTERNET_CACHE, NULL,
SHGFP_TYPE_CURRENT, &tif_pidl);
- DCHECK(SUCCEEDED(hr) && tif_pidl);
-
- ScopedComPtr<IShellFolder> parent_folder;
- LPCITEMIDLIST relative_pidl = NULL;
- hr = SHBindToParent(tif_pidl, IID_IShellFolder,
- reinterpret_cast<void**>(parent_folder.Receive()),
- &relative_pidl);
- DCHECK(SUCCEEDED(hr) && relative_pidl);
-
- STRRET path = {0};
- hr = parent_folder->GetDisplayNameOf(relative_pidl,
- SHGDN_NORMAL | SHGDN_FORPARSING,
- &path);
- DCHECK(SUCCEEDED(hr));
- ScopedBstr tif_bstr;
- StrRetToBSTR(&path, relative_pidl, tif_bstr.Receive());
- FilePath tif(static_cast<BSTR>(tif_bstr));
-
- ILFree(tif_pidl);
- return tif;
+ if (SUCCEEDED(hr) && tif_pidl) {
+ ScopedComPtr<IShellFolder> parent_folder;
+ LPITEMIDLIST relative_pidl = NULL;
+ hr = SHBindToParent(tif_pidl, IID_IShellFolder,
+ reinterpret_cast<void**>(parent_folder.Receive()),
+ const_cast<LPCITEMIDLIST*>(&relative_pidl));
+ if (SUCCEEDED(hr) && relative_pidl) {
+ STRRET path = {0};
+ hr = parent_folder->GetDisplayNameOf(relative_pidl,
+ SHGDN_NORMAL | SHGDN_FORPARSING,
+ &path);
+ DCHECK(SUCCEEDED(hr));
+ ScopedBstr temp_internet_files_bstr;
+ StrRetToBSTR(&path, relative_pidl, temp_internet_files_bstr.Receive());
+ FilePath temp_internet_files(static_cast<BSTR>(temp_internet_files_bstr));
+
+ ILFree(relative_pidl);
+ ILFree(tif_pidl);
+ return temp_internet_files;
+ } else {
+ NOTREACHED() << "SHBindToParent failed with Error:" << hr;
+ ILFree(tif_pidl);
+ }
+ } else {
+ NOTREACHED() << "SHGetFolderLocation for internet cache failed. Error:"
+ << hr;
+ }
+ // As a last ditch effort we use the SHGetFolderPath function to retrieve the
+ // path. This function has a limitation of MAX_PATH.
+ wchar_t path[MAX_PATH + 1] = {0};
+ hr = SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL, SHGFP_TYPE_CURRENT,
+ path);
+ if (SUCCEEDED(hr)) {
+ return FilePath(path);
+ } else {
+ NOTREACHED() << "SHGetFolderPath for internet cache failed. Error:"
+ << hr;
+ }
+ return FilePath();
}
bool IsIEInPrivate() {