From c607aa3f2bfeb4170055251af40e849206a6931c Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Sat, 23 Aug 2008 17:32:17 +0000 Subject: [PATCH] - Check if source and destination is the same. Fixes creating a new directory and using the default name - Prevent a potential buffer overflow in the file properties dialog svn path=/trunk/; revision=35570 --- reactos/dll/win32/shell32/fprop.c | 16 ++++++++++------ reactos/dll/win32/shell32/shfldr_desktop.c | 10 ++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/reactos/dll/win32/shell32/fprop.c b/reactos/dll/win32/shell32/fprop.c index 2a72394649f..a037b8ff225 100644 --- a/reactos/dll/win32/shell32/fprop.c +++ b/reactos/dll/win32/shell32/fprop.c @@ -664,7 +664,7 @@ BOOL CALLBACK AddShellPropSheetExCallback(HPROPSHEETPAGE hPage, LPARAM lParam) int EnumPropSheetExt(LPWSTR wFileName, PROPSHEETHEADERW *pinfo, int NumPages, HPSXA * hpsxa, IDataObject *pDataObj) { - WCHAR szName[100]; + WCHAR szName[MAX_PATH] = {0}; WCHAR * pOffset; UINT Length; DWORD dwName; @@ -675,7 +675,7 @@ EnumPropSheetExt(LPWSTR wFileName, PROPSHEETHEADERW *pinfo, int NumPages, HPSXA if (!pOffset) { Length = wcslen(szName); - if (Length >=94) + if (Length + 6 > sizeof(szName)/sizeof(szName[0])) return 0; if (CLSIDFromString(wFileName, &clsid) == NOERROR) @@ -691,7 +691,7 @@ EnumPropSheetExt(LPWSTR wFileName, PROPSHEETHEADERW *pinfo, int NumPages, HPSXA else { Length = wcslen(pOffset); - if (Length >= 100) + if (Length >= sizeof(szName)/sizeof(szName[0])) return 0; wcscpy(szName, pOffset); } @@ -799,7 +799,11 @@ SH_ShowPropertiesDialog(WCHAR * lpf, LPCITEMIDLIST pidlFolder, LPCITEMIDLIST * a hResult = SHCreateDataObject(pidlFolder, 1, apidl, NULL, &IID_IDataObject, (LPVOID*)&pDataObj); if (hResult == S_OK) { - EnumPropSheetExt(wFileName, &pinfo, MAX_PROPERTY_SHEET_PAGE-1, hpsxa, pDataObj); + if (!EnumPropSheetExt(wFileName, &pinfo, MAX_PROPERTY_SHEET_PAGE-1, hpsxa, pDataObj)) + { + hpsxa[0] = NULL; + hpsxa[1] = NULL; + } } if ( GetFileVersionInfoSizeW(lpf, &dwHandle)) @@ -813,8 +817,8 @@ SH_ShowPropertiesDialog(WCHAR * lpf, LPCITEMIDLIST pidlFolder, LPCITEMIDLIST * a if (hResult == S_OK) { - SHDestroyPropSheetExtArray(hpsxa[0]); - SHDestroyPropSheetExtArray(hpsxa[1]); + SHDestroyPropSheetExtArray(hpsxa[0]); + SHDestroyPropSheetExtArray(hpsxa[1]); IDataObject_Release(pDataObj); } diff --git a/reactos/dll/win32/shell32/shfldr_desktop.c b/reactos/dll/win32/shell32/shfldr_desktop.c index bbe8e6844da..a14cb443f9f 100644 --- a/reactos/dll/win32/shell32/shfldr_desktop.c +++ b/reactos/dll/win32/shell32/shfldr_desktop.c @@ -864,6 +864,16 @@ static HRESULT WINAPI ISF_Desktop_fnSetNameOf (IShellFolder2 * iface, } } + if (!memcmp(szSrc, szDest, (wcslen(szDest)+1) * sizeof(WCHAR))) + { + /* src and destination is the same */ + hr = S_OK; + if (pPidlOut) + hr = _ILCreateFromPathW(szDest, pPidlOut); + + return hr; + } + TRACE ("src=%s dest=%s\n", debugstr_w(szSrc), debugstr_w(szDest)); if (MoveFileW (szSrc, szDest)) {