[1/2] shell32: fix CommandLineToArgvW("") truncating returned exe path.
Ilya Basin
basinilya at gmail.com
Tue Jul 6 14:37:08 CDT 2010
This fixes http://bugs.winehq.org/show_bug.cgi?id=21758
Currently CommandLineToArgvW("") returns only the first 6 characters
of the exe path. And even worse, it doesn't terminate the result
string with 0, which can potentially cause access violations.
Here's the crosstest output:
[il at IL wine-git]$ ./wine dlls/shell32/tests/shell32_crosstest.exe shlexec
...
shlexec.c:2182: Test failed: wrong path to the current executable
expected: L"Z:\\home\\il\\builds\\wine-git\\dlls\\shell32\\tests\\shell32_crosstest.exe"
got : L"Z:\\homCe\64d0\0013("
shlexec: 411 tests executed (0 marked as todo, 21 failures), 0 skipped.
---
dlls/shell32/shell32_main.c | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/dlls/shell32/shell32_main.c b/dlls/shell32/shell32_main.c
index 2824268..4fb0863 100644
--- a/dlls/shell32/shell32_main.c
+++ b/dlls/shell32/shell32_main.c
@@ -93,20 +93,22 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
if (*lpCmdline==0)
{
/* Return the path to the executable */
- DWORD len, size=16;
+ DWORD len, deslen=MAX_PATH, size;
+ size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
argv=LocalAlloc(LMEM_FIXED, size);
for (;;)
{
- len = GetModuleFileNameW(0, (LPWSTR)(argv+1), (size-sizeof(LPWSTR))/sizeof(WCHAR));
+ len = GetModuleFileNameW(0, (LPWSTR)(argv+1), deslen);
if (!len)
{
LocalFree(argv);
return NULL;
}
- if (len < size) break;
- size*=2;
- argv=LocalReAlloc(argv, size, 0);
+ if (len < deslen) break;
+ deslen*=2;
+ size = sizeof(LPWSTR) + deslen*sizeof(WCHAR) + sizeof(LPWSTR);
+ argv=LocalReAlloc(argv, size, LMEM_MOVEABLE);
}
argv[0]=(LPWSTR)(argv+1);
if (numargs)
--
1.7.1.1
More information about the wine-patches
mailing list