Commit df93f2ee authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

GetModuleFileName[AW] doesn't terminate the string if the buffer is

too small.
parent 48a86598
...@@ -312,9 +312,12 @@ static HRESULT register_clsids(int count, const register_info * pRegInfo, LPCWST ...@@ -312,9 +312,12 @@ static HRESULT register_clsids(int count, const register_info * pRegInfo, LPCWST
== ERROR_SUCCESS ? S_OK : E_FAIL; == ERROR_SUCCESS ? S_OK : E_FAIL;
TRACE("HModule = %p\n", DEVENUM_hInstance); TRACE("HModule = %p\n", DEVENUM_hInstance);
if (!GetModuleFileNameW(DEVENUM_hInstance, dll_module, i = GetModuleFileNameW(DEVENUM_hInstance, dll_module,
sizeof(dll_module) / sizeof(WCHAR))) sizeof(dll_module) / sizeof(WCHAR));
if (!i)
return HRESULT_FROM_WIN32(GetLastError()); return HRESULT_FROM_WIN32(GetLastError());
if (i >= sizeof(dll_module) / sizeof(WCHAR))
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
......
...@@ -143,6 +143,7 @@ void setup_dsound_options(void) ...@@ -143,6 +143,7 @@ void setup_dsound_options(void)
{ {
char buffer[MAX_PATH+1]; char buffer[MAX_PATH+1];
HKEY hkey, appkey = 0; HKEY hkey, appkey = 0;
DWORD len;
buffer[MAX_PATH]='\0'; buffer[MAX_PATH]='\0';
...@@ -153,7 +154,8 @@ void setup_dsound_options(void) ...@@ -153,7 +154,8 @@ void setup_dsound_options(void)
ExitProcess(1); ExitProcess(1);
} }
if (GetModuleFileNameA( 0, buffer, MAX_PATH )) len = GetModuleFileNameA( 0, buffer, MAX_PATH );
if (len && len < MAX_PATH)
{ {
HKEY tmpkey; HKEY tmpkey;
......
...@@ -1133,7 +1133,10 @@ BOOL WINAPI AllocConsole(void) ...@@ -1133,7 +1133,10 @@ BOOL WINAPI AllocConsole(void)
if (siCurrent.lpTitle) if (siCurrent.lpTitle)
siConsole.lpTitle = siCurrent.lpTitle; siConsole.lpTitle = siCurrent.lpTitle;
else if (GetModuleFileNameA(0, buffer, sizeof(buffer))) else if (GetModuleFileNameA(0, buffer, sizeof(buffer)))
{
buffer[sizeof(buffer) - 1] = '\0';
siConsole.lpTitle = buffer; siConsole.lpTitle = buffer;
}
if (!start_console_renderer(&siConsole)) if (!start_console_renderer(&siConsole))
goto the_end; goto the_end;
......
...@@ -432,6 +432,8 @@ HMODULE WINAPI GetModuleHandleW(LPCWSTR module) ...@@ -432,6 +432,8 @@ HMODULE WINAPI GetModuleHandleW(LPCWSTR module)
* This function always returns the long path of hModule (as opposed to * This function always returns the long path of hModule (as opposed to
* GetModuleFileName16() which returns short paths when the modules version * GetModuleFileName16() which returns short paths when the modules version
* field is < 4.0). * field is < 4.0).
* The function doesn't write a terminating '\0' is the buffer is too
* small.
*/ */
DWORD WINAPI GetModuleFileNameA( DWORD WINAPI GetModuleFileNameA(
HMODULE hModule, /* [in] Module handle (32 bit) */ HMODULE hModule, /* [in] Module handle (32 bit) */
...@@ -439,16 +441,20 @@ DWORD WINAPI GetModuleFileNameA( ...@@ -439,16 +441,20 @@ DWORD WINAPI GetModuleFileNameA(
DWORD size ) /* [in] Size of lpFileName in characters */ DWORD size ) /* [in] Size of lpFileName in characters */
{ {
LPWSTR filenameW = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ); LPWSTR filenameW = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) );
DWORD len;
if (!filenameW) if (!filenameW)
{ {
SetLastError( ERROR_NOT_ENOUGH_MEMORY ); SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return 0; return 0;
} }
GetModuleFileNameW( hModule, filenameW, size ); if ((len = GetModuleFileNameW( hModule, filenameW, size )))
FILE_name_WtoA( filenameW, -1, lpFileName, size ); {
len = FILE_name_WtoA( filenameW, len, lpFileName, size );
if (len < size) lpFileName[len] = '\0';
}
HeapFree( GetProcessHeap(), 0, filenameW ); HeapFree( GetProcessHeap(), 0, filenameW );
return strlen( lpFileName ); return len;
} }
/*********************************************************************** /***********************************************************************
...@@ -458,16 +464,16 @@ DWORD WINAPI GetModuleFileNameA( ...@@ -458,16 +464,16 @@ DWORD WINAPI GetModuleFileNameA(
*/ */
DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, DWORD size ) DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, DWORD size )
{ {
ULONG magic; ULONG magic, len = 0;
LDR_MODULE *pldr; LDR_MODULE *pldr;
NTSTATUS nts; NTSTATUS nts;
WIN16_SUBSYSTEM_TIB *win16_tib; WIN16_SUBSYSTEM_TIB *win16_tib;
lpFileName[0] = 0;
if (!hModule && ((win16_tib = NtCurrentTeb()->Tib.SubSystemTib)) && win16_tib->exe_name) if (!hModule && ((win16_tib = NtCurrentTeb()->Tib.SubSystemTib)) && win16_tib->exe_name)
{ {
lstrcpynW( lpFileName, win16_tib->exe_name->Buffer, size ); len = min(size, win16_tib->exe_name->Length / sizeof(WCHAR));
memcpy( lpFileName, win16_tib->exe_name->Buffer, len * sizeof(WCHAR) );
if (len < size) lpFileName[len] = '\0';
goto done; goto done;
} }
...@@ -475,13 +481,18 @@ DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, DWORD size ...@@ -475,13 +481,18 @@ DWORD WINAPI GetModuleFileNameW( HMODULE hModule, LPWSTR lpFileName, DWORD size
if (!hModule) hModule = NtCurrentTeb()->Peb->ImageBaseAddress; if (!hModule) hModule = NtCurrentTeb()->Peb->ImageBaseAddress;
nts = LdrFindEntryForAddress( hModule, &pldr ); nts = LdrFindEntryForAddress( hModule, &pldr );
if (nts == STATUS_SUCCESS) lstrcpynW(lpFileName, pldr->FullDllName.Buffer, size); if (nts == STATUS_SUCCESS)
{
len = min(size, pldr->FullDllName.Length / sizeof(WCHAR));
memcpy(lpFileName, pldr->FullDllName.Buffer, len * sizeof(WCHAR));
if (len < size) lpFileName[len] = '\0';
}
else SetLastError( RtlNtStatusToDosError( nts ) ); else SetLastError( RtlNtStatusToDosError( nts ) );
LdrUnlockLoaderLock( 0, magic ); LdrUnlockLoaderLock( 0, magic );
done: done:
TRACE( "%s\n", debugstr_w(lpFileName) ); TRACE( "%s\n", debugstr_wn(lpFileName, len) );
return strlenW(lpFileName); return len;
} }
......
...@@ -2095,7 +2095,8 @@ static HMODULE16 create_dummy_module( HMODULE module32 ) ...@@ -2095,7 +2095,8 @@ static HMODULE16 create_dummy_module( HMODULE module32 )
if (!nt) return (HMODULE16)11; /* invalid exe */ if (!nt) return (HMODULE16)11; /* invalid exe */
/* Extract base filename */ /* Extract base filename */
GetModuleFileNameA( module32, filename, sizeof(filename) ); len = GetModuleFileNameA( module32, filename, sizeof(filename) );
if (!len || len >= sizeof(filename)) return (HMODULE16)11; /* invalid exe */
basename = strrchr(filename, '\\'); basename = strrchr(filename, '\\');
if (!basename) basename = filename; if (!basename) basename = filename;
else basename++; else basename++;
......
...@@ -14,6 +14,7 @@ generated.ok ...@@ -14,6 +14,7 @@ generated.ok
heap.ok heap.ok
locale.ok locale.ok
mailslot.ok mailslot.ok
module.ok
path.ok path.ok
pipe.ok pipe.ok
process.ok process.ok
......
...@@ -20,6 +20,7 @@ CTESTS = \ ...@@ -20,6 +20,7 @@ CTESTS = \
generated.c \ generated.c \
heap.c \ heap.c \
locale.c \ locale.c \
module.c \
mailslot.c \ mailslot.c \
path.c \ path.c \
pipe.c \ pipe.c \
......
/*
* Unit tests for module/DLL/library API
*
* Copyright (c) 2004 Eric Pouech
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "wine/test.h"
#include "wine/debug.h"
#include <windows.h>
static BOOL cmpStrAW(const char* a, const WCHAR* b, DWORD len)
{
WCHAR aw[1024];
MultiByteToWideChar( CP_ACP, 0, a, len, aw, sizeof(aw) / sizeof(aw[0]) );
return memcmp(aw, b, len * sizeof(WCHAR)) == 0;
}
static void testGetModuleFileName(const char* name)
{
HMODULE hMod;
char bufA[MAX_PATH];
WCHAR bufW[MAX_PATH];
DWORD len1A, len1W, len2A, len2W, l;
hMod = (name) ? GetModuleHandle(name) : NULL;
/* first test, with enough space in buffer */
memset(bufA, '-', sizeof(bufA));
len1A = GetModuleFileNameA(hMod, bufA, sizeof(bufA));
ok(len1A > 0, "Getting module filename for handle %p\n", hMod);
memset(bufW, '-', sizeof(bufW));
len1W = GetModuleFileNameW(hMod, bufW, sizeof(bufW) / sizeof(WCHAR));
ok(len1W > 0, "Getting module filename for handle %p\n", hMod);
ok(len1A == len1W, "Didn't get same A/W lengths (%ld/%ld)\n", len1A, len1W);
ok(len1A == strlen(bufA), "Unexpected length of GetModuleFilenameA (%ld/%d)\n", len1A, strlen(bufA));
ok(len1W == lstrlenW(bufW), "Unexpected length of GetModuleFilenameW (%ld/%d)\n", len1W, lstrlenW(bufW));
ok(cmpStrAW(bufA, bufW, l = min(len1A, len1W)), "Comparing GetModuleFilenameAW results\n");
/* second test with a buffer too small */
memset(bufA, '-', sizeof(bufA));
len2A = GetModuleFileNameA(hMod, bufA, len1A / 2);
ok(len2A > 0, "Getting module filename for handle %p\n", hMod);
memset(bufW, '-', sizeof(bufW));
len2W = GetModuleFileNameW(hMod, bufW, len1W / 2);
ok(len2W > 0, "Getting module filename for handle %p\n", hMod);
ok(len2A == len2W, "Didn't get same A/W lengths (%ld/%ld)\n", len2A, len2W);
l = min(len2A, len2W);
ok(cmpStrAW(bufA, bufW, l), "Comparing GetModuleFilenameAW results with buffer too small %s / %s\n", wine_dbgstr_an(bufA, l), wine_dbgstr_wn(bufW, l));
ok(len1A / 2 == len2A, "Correct length in GetModuleFilenameA with buffer too small (%ld/%ld)\n", len1A / 2, len2A);
ok(len1W / 2 == len2W, "Correct length in GetModuleFilenameW with buffer too small (%ld/%ld)\n", len1W / 2, len2W);
}
static void testGetModuleFileName_Wrong(void)
{
char bufA[MAX_PATH];
WCHAR bufW[MAX_PATH];
/* test wrong handle */
bufW[0] = '*';
ok(GetModuleFileNameW((void*)0xffffffff, bufW, sizeof(bufW) / sizeof(WCHAR)) == 0, "Unexpected success in module handle\n");
ok(bufW[0] == '*', "When failing, buffer shouldn't be written to\n");
bufA[0] = '*';
ok(GetModuleFileNameA((void*)0xffffffff, bufA, sizeof(bufA)) == 0, "Unexpected success in module handle\n");
ok(bufA[0] == '*', "When failing, buffer shouldn't be written to\n");
}
START_TEST(module)
{
testGetModuleFileName(NULL);
testGetModuleFileName("kernel32.dll");
testGetModuleFileName_Wrong();
}
...@@ -82,6 +82,7 @@ WORD get_dos_version(void) ...@@ -82,6 +82,7 @@ WORD get_dos_version(void)
HKEY hkey, config_key; HKEY hkey, config_key;
WCHAR buffer[MAX_PATH]; WCHAR buffer[MAX_PATH];
WORD ret = 0; WORD ret = 0;
DWORD len;
static const WCHAR configW[] = {'M','a','c','h','i','n','e','\\', static const WCHAR configW[] = {'M','a','c','h','i','n','e','\\',
'S','o','f','t','w','a','r','e','\\', 'S','o','f','t','w','a','r','e','\\',
...@@ -103,7 +104,8 @@ WORD get_dos_version(void) ...@@ -103,7 +104,8 @@ WORD get_dos_version(void)
attr.RootDirectory = config_key; attr.RootDirectory = config_key;
/* open AppDefaults\\appname\\Version key */ /* open AppDefaults\\appname\\Version key */
if (GetModuleFileNameW( 0, buffer, sizeof(buffer)/sizeof(WCHAR) )) len = GetModuleFileNameW( 0, buffer, sizeof(buffer)/sizeof(WCHAR) );
if (len && len < sizeof(buffer)/sizeof(WCHAR))
{ {
WCHAR *p, *appname, appversion[MAX_PATH+20]; WCHAR *p, *appname, appversion[MAX_PATH+20];
......
...@@ -293,11 +293,21 @@ void msvcrt_init_args(void) ...@@ -293,11 +293,21 @@ void msvcrt_init_args(void)
MSVCRT__pgmptr = HeapAlloc(GetProcessHeap(), 0, MAX_PATH); MSVCRT__pgmptr = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
if (MSVCRT__pgmptr) if (MSVCRT__pgmptr)
GetModuleFileNameA(0, MSVCRT__pgmptr, MAX_PATH); {
if (!GetModuleFileNameA(0, MSVCRT__pgmptr, MAX_PATH))
MSVCRT__pgmptr[0] = '\0';
else
MSVCRT__pgmptr[MAX_PATH - 1] = '\0';
}
MSVCRT__wpgmptr = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR)); MSVCRT__wpgmptr = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
if (MSVCRT__wpgmptr) if (MSVCRT__wpgmptr)
GetModuleFileNameW(0, MSVCRT__wpgmptr, MAX_PATH); {
if (!GetModuleFileNameW(0, MSVCRT__wpgmptr, MAX_PATH))
MSVCRT__wpgmptr[0] = '\0';
else
MSVCRT__wpgmptr[MAX_PATH - 1] = '\0';
}
} }
......
...@@ -348,7 +348,11 @@ DWORD WINAPI GetModuleFileNameExA(HANDLE hProcess, HMODULE hModule, ...@@ -348,7 +348,11 @@ DWORD WINAPI GetModuleFileNameExA(HANDLE hProcess, HMODULE hModule,
if (!lpFileName || !nSize) return 0; if (!lpFileName || !nSize) return 0;
if ( hProcess == GetCurrentProcess() ) if ( hProcess == GetCurrentProcess() )
return GetModuleFileNameA( hModule, lpFileName, nSize ); {
DWORD len = GetModuleFileNameA( hModule, lpFileName, nSize );
if (nSize) lpFileName[nSize - 1] = '\0';
return len;
}
if (!(ptr = HeapAlloc(GetProcessHeap(), 0, nSize * sizeof(WCHAR)))) return 0; if (!(ptr = HeapAlloc(GetProcessHeap(), 0, nSize * sizeof(WCHAR)))) return 0;
...@@ -380,7 +384,11 @@ DWORD WINAPI GetModuleFileNameExW(HANDLE hProcess, HMODULE hModule, ...@@ -380,7 +384,11 @@ DWORD WINAPI GetModuleFileNameExW(HANDLE hProcess, HMODULE hModule,
if (!lpFileName || !nSize) return 0; if (!lpFileName || !nSize) return 0;
if ( hProcess == GetCurrentProcess() ) if ( hProcess == GetCurrentProcess() )
return GetModuleFileNameW( hModule, lpFileName, nSize ); {
DWORD len = GetModuleFileNameW( hModule, lpFileName, nSize );
if (nSize) lpFileName[nSize - 1] = '\0';
return len;
}
lpFileName[0] = 0; lpFileName[0] = 0;
......
...@@ -159,8 +159,9 @@ HRESULT WINAPI NdrDllRegisterProxy(HMODULE hDll, ...@@ -159,8 +159,9 @@ HRESULT WINAPI NdrDllRegisterProxy(HMODULE hDll,
const CLSID *pclsid) const CLSID *pclsid)
{ {
LPSTR clsid; LPSTR clsid;
char keyname[120], module[120]; char keyname[120], module[MAX_PATH];
HKEY key, subkey; HKEY key, subkey;
DWORD len;
TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid)); TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid));
UuidToStringA((UUID*)pclsid, (unsigned char**)&clsid); UuidToStringA((UUID*)pclsid, (unsigned char**)&clsid);
...@@ -196,7 +197,8 @@ HRESULT WINAPI NdrDllRegisterProxy(HMODULE hDll, ...@@ -196,7 +197,8 @@ HRESULT WINAPI NdrDllRegisterProxy(HMODULE hDll,
/* register clsid to point to module */ /* register clsid to point to module */
snprintf(keyname, sizeof(keyname), "CLSID\\{%s}", clsid); snprintf(keyname, sizeof(keyname), "CLSID\\{%s}", clsid);
GetModuleFileNameA(hDll, module, sizeof(module)); len = GetModuleFileNameA(hDll, module, sizeof(module));
if (len && len < sizeof(module)) {
TRACE("registering CLSID %s => %s\n", clsid, module); TRACE("registering CLSID %s => %s\n", clsid, module);
if (RegCreateKeyExA(HKEY_CLASSES_ROOT, keyname, 0, NULL, 0, if (RegCreateKeyExA(HKEY_CLASSES_ROOT, keyname, 0, NULL, 0,
KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS) { KEY_WRITE, NULL, &key, NULL) == ERROR_SUCCESS) {
...@@ -207,6 +209,7 @@ HRESULT WINAPI NdrDllRegisterProxy(HMODULE hDll, ...@@ -207,6 +209,7 @@ HRESULT WINAPI NdrDllRegisterProxy(HMODULE hDll,
} }
RegCloseKey(key); RegCloseKey(key);
} }
}
/* done */ /* done */
RpcStringFreeA((unsigned char**)&clsid); RpcStringFreeA((unsigned char**)&clsid);
...@@ -221,7 +224,8 @@ HRESULT WINAPI NdrDllUnregisterProxy(HMODULE hDll, ...@@ -221,7 +224,8 @@ HRESULT WINAPI NdrDllUnregisterProxy(HMODULE hDll,
const CLSID *pclsid) const CLSID *pclsid)
{ {
LPSTR clsid; LPSTR clsid;
char keyname[120], module[120]; char keyname[120], module[MAX_PATH];
DWORD len;
TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid)); TRACE("(%p,%p,%s)\n", hDll, pProxyFileList, debugstr_guid(pclsid));
UuidToStringA((UUID*)pclsid, (unsigned char**)&clsid); UuidToStringA((UUID*)pclsid, (unsigned char**)&clsid);
...@@ -246,9 +250,11 @@ HRESULT WINAPI NdrDllUnregisterProxy(HMODULE hDll, ...@@ -246,9 +250,11 @@ HRESULT WINAPI NdrDllUnregisterProxy(HMODULE hDll,
/* unregister clsid */ /* unregister clsid */
snprintf(keyname, sizeof(keyname), "CLSID\\{%s}", clsid); snprintf(keyname, sizeof(keyname), "CLSID\\{%s}", clsid);
GetModuleFileNameA(hDll, module, sizeof(module)); len = GetModuleFileNameA(hDll, module, sizeof(module));
if (len && len < sizeof(module)) {
TRACE("unregistering CLSID %s <= %s\n", clsid, module); TRACE("unregistering CLSID %s <= %s\n", clsid, module);
RegDeleteKeyA(HKEY_CLASSES_ROOT, keyname); RegDeleteKeyA(HKEY_CLASSES_ROOT, keyname);
}
/* done */ /* done */
RpcStringFreeA((unsigned char**)&clsid); RpcStringFreeA((unsigned char**)&clsid);
......
...@@ -490,9 +490,13 @@ HICON WINAPI ExtractAssociatedIconA(HINSTANCE hInst, LPSTR lpIconPath, LPWORD lp ...@@ -490,9 +490,13 @@ HICON WINAPI ExtractAssociatedIconA(HINSTANCE hInst, LPSTR lpIconPath, LPWORD lp
else else
*lpiIcon = 6; /* generic icon - found nothing */ *lpiIcon = 6; /* generic icon - found nothing */
GetModuleFileNameA(hInst, lpIconPath, 0x80); if (GetModuleFileNameA(hInst, lpIconPath, 0x80))
{
/* terminate string (GetModuleFileName doesn't do if buffer is too small) */
lpIconPath[0x80 - 1] = '\0';
hIcon = LoadIconA( hInst, MAKEINTRESOURCEA(*lpiIcon)); hIcon = LoadIconA( hInst, MAKEINTRESOURCEA(*lpiIcon));
} }
}
return hIcon; return hIcon;
} }
......
...@@ -91,11 +91,17 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs) ...@@ -91,11 +91,17 @@ LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
if (*lpCmdline==0) { if (*lpCmdline==0) {
/* Return the path to the executable */ /* Return the path to the executable */
DWORD size=16; DWORD len, size=16;
hargv=GlobalAlloc(size, 0); hargv=GlobalAlloc(size, 0);
argv=GlobalLock(hargv); argv=GlobalLock(hargv);
while (GetModuleFileNameW(0, (LPWSTR)(argv+1), size-sizeof(LPWSTR)) == 0) { for (;;) {
len = GetModuleFileNameW(0, (LPWSTR)(argv+1), size-sizeof(LPWSTR));
if (!len) {
GlobalFree(hargv);
return NULL;
}
if (len < size) break;
size*=2; size*=2;
hargv=GlobalReAlloc(hargv, size, 0); hargv=GlobalReAlloc(hargv, size, 0);
argv=GlobalLock(hargv); argv=GlobalLock(hargv);
...@@ -932,6 +938,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad) ...@@ -932,6 +938,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
/* get full path to this DLL for IExtractIconW_fnGetIconLocation() */ /* get full path to this DLL for IExtractIconW_fnGetIconLocation() */
GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH); GetModuleFileNameW(hinstDLL, swShell32Name, MAX_PATH);
swShell32Name[MAX_PATH - 1] = '\0';
InitCommonControlsEx(NULL); InitCommonControlsEx(NULL);
......
...@@ -3265,9 +3265,12 @@ HMODULE WINAPI MLLoadLibraryA(LPCSTR new_mod, HMODULE inst_hwnd, DWORD dwFlags) ...@@ -3265,9 +3265,12 @@ HMODULE WINAPI MLLoadLibraryA(LPCSTR new_mod, HMODULE inst_hwnd, DWORD dwFlags)
*/ */
CHAR mod_path[2*MAX_PATH]; CHAR mod_path[2*MAX_PATH];
LPSTR ptr; LPSTR ptr;
DWORD len;
FIXME("(%s,%p,0x%08lx) semi-stub!\n", debugstr_a(new_mod), inst_hwnd, dwFlags); FIXME("(%s,%p,0x%08lx) semi-stub!\n", debugstr_a(new_mod), inst_hwnd, dwFlags);
GetModuleFileNameA(inst_hwnd, mod_path, 2*MAX_PATH); len = GetModuleFileNameA(inst_hwnd, mod_path, sizeof(mod_path));
if (!len || len >= sizeof(mod_path)) return NULL;
ptr = strrchr(mod_path, '\\'); ptr = strrchr(mod_path, '\\');
if (ptr) { if (ptr) {
strcpy(ptr+1, new_mod); strcpy(ptr+1, new_mod);
...@@ -3286,9 +3289,12 @@ HMODULE WINAPI MLLoadLibraryW(LPCWSTR new_mod, HMODULE inst_hwnd, DWORD dwFlags) ...@@ -3286,9 +3289,12 @@ HMODULE WINAPI MLLoadLibraryW(LPCWSTR new_mod, HMODULE inst_hwnd, DWORD dwFlags)
{ {
WCHAR mod_path[2*MAX_PATH]; WCHAR mod_path[2*MAX_PATH];
LPWSTR ptr; LPWSTR ptr;
DWORD len;
FIXME("(%s,%p,0x%08lx) semi-stub!\n", debugstr_w(new_mod), inst_hwnd, dwFlags); FIXME("(%s,%p,0x%08lx) semi-stub!\n", debugstr_w(new_mod), inst_hwnd, dwFlags);
GetModuleFileNameW(inst_hwnd, mod_path, 2*MAX_PATH); len = GetModuleFileNameW(inst_hwnd, mod_path, sizeof(mod_path) / sizeof(WCHAR));
if (!len || len >= sizeof(mod_path) / sizeof(WCHAR)) return NULL;
ptr = strrchrW(mod_path, '\\'); ptr = strrchrW(mod_path, '\\');
if (ptr) { if (ptr) {
strcpyW(ptr+1, new_mod); strcpyW(ptr+1, new_mod);
......
...@@ -2428,8 +2428,10 @@ HRESULT WINAPI MLBuildResURLW(LPCWSTR lpszLibName, HMODULE hMod, DWORD dwFlags, ...@@ -2428,8 +2428,10 @@ HRESULT WINAPI MLBuildResURLW(LPCWSTR lpszLibName, HMODULE hMod, DWORD dwFlags,
if (hMod) if (hMod)
{ {
WCHAR szBuff[MAX_PATH]; WCHAR szBuff[MAX_PATH];
DWORD len;
if (GetModuleFileNameW(hMod, szBuff, sizeof(szBuff)/sizeof(WCHAR))) len = GetModuleFileNameW(hMod, szBuff, sizeof(szBuff)/sizeof(WCHAR));
if (len && len < sizeof(szBuff)/sizeof(WCHAR))
{ {
DWORD dwPathLen = strlenW(szBuff) + 1; DWORD dwPathLen = strlenW(szBuff) + 1;
......
...@@ -122,6 +122,7 @@ static HHOOK set_windows_hook( INT id, HOOKPROC proc, HINSTANCE inst, DWORD tid, ...@@ -122,6 +122,7 @@ static HHOOK set_windows_hook( INT id, HOOKPROC proc, HINSTANCE inst, DWORD tid,
{ {
HHOOK handle = 0; HHOOK handle = 0;
WCHAR module[MAX_PATH]; WCHAR module[MAX_PATH];
DWORD len;
if (tid) /* thread-local hook */ if (tid) /* thread-local hook */
{ {
...@@ -140,7 +141,7 @@ static HHOOK set_windows_hook( INT id, HOOKPROC proc, HINSTANCE inst, DWORD tid, ...@@ -140,7 +141,7 @@ static HHOOK set_windows_hook( INT id, HOOKPROC proc, HINSTANCE inst, DWORD tid,
else /* system-global hook */ else /* system-global hook */
{ {
if (id == WH_KEYBOARD_LL || id == WH_MOUSE_LL) inst = 0; if (id == WH_KEYBOARD_LL || id == WH_MOUSE_LL) inst = 0;
else if (!inst || !GetModuleFileNameW( inst, module, MAX_PATH )) else if (!inst || !(len = GetModuleFileNameW( inst, module, MAX_PATH )) || len >= MAX_PATH)
{ {
SetLastError( ERROR_INVALID_PARAMETER ); SetLastError( ERROR_INVALID_PARAMETER );
return 0; return 0;
......
...@@ -441,7 +441,6 @@ END: ...@@ -441,7 +441,6 @@ END:
DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle ) DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle )
{ {
DWORD ret, offset, len = (filename && strlenW(filename)) ? strlenW(filename) + 1: MAX_PATH; DWORD ret, offset, len = (filename && strlenW(filename)) ? strlenW(filename) + 1: MAX_PATH;
DWORD nSize = len;
LPSTR filenameA = NULL; LPSTR filenameA = NULL;
LPWSTR filenameW; LPWSTR filenameW;
VS_FIXEDFILEINFO *vffi; VS_FIXEDFILEINFO *vffi;
...@@ -453,9 +452,12 @@ DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle ) ...@@ -453,9 +452,12 @@ DWORD WINAPI GetFileVersionInfoSizeW( LPCWSTR filename, LPDWORD handle )
if (filename && strlenW(filename)) if (filename && strlenW(filename))
strcpyW(filenameW, filename); strcpyW(filenameW, filename);
else { else {
nSize = GetModuleFileNameW(NULL, filenameW, nSize); DWORD nSize = GetModuleFileNameW(NULL, filenameW, len);
if((nSize +1) >= len) if (!nSize || nSize >= len)
FIXME("buffer may be too small\n"); {
len = 0;
goto End;
}
} }
len = VERSION_GetFileVersionInfo_PE(filenameW, handle, 0, NULL); len = VERSION_GetFileVersionInfo_PE(filenameW, handle, 0, NULL);
......
...@@ -90,8 +90,11 @@ static HMMIO get_mmioFromProfile(UINT uFlags, LPCWSTR lpszName) ...@@ -90,8 +90,11 @@ static HMMIO get_mmioFromProfile(UINT uFlags, LPCWSTR lpszName)
if (RegOpenKeyW(HKEY_CURRENT_USER, wszKey, &hRegSnd) != 0) goto none; if (RegOpenKeyW(HKEY_CURRENT_USER, wszKey, &hRegSnd) != 0) goto none;
if (uFlags & SND_APPLICATION) if (uFlags & SND_APPLICATION)
{ {
DWORD len;
err = 1; /* error */ err = 1; /* error */
if (GetModuleFileNameW(0, str, sizeof(str)/sizeof(str[0]))) len = GetModuleFileNameW(0, str, sizeof(str)/sizeof(str[0]));
if (len > 0 && len < sizeof(str)/sizeof(str[0]))
{ {
for (ptr = str + lstrlenW(str) - 1; ptr >= str; ptr--) for (ptr = str + lstrlenW(str) - 1; ptr >= str; ptr--)
{ {
......
...@@ -239,6 +239,7 @@ static void setup_options(void) ...@@ -239,6 +239,7 @@ static void setup_options(void)
{ {
char buffer[MAX_PATH+16]; char buffer[MAX_PATH+16];
HKEY hkey, appkey = 0; HKEY hkey, appkey = 0;
DWORD len;
if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\x11drv", 0, NULL, if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\x11drv", 0, NULL,
REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL )) REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
...@@ -249,7 +250,8 @@ static void setup_options(void) ...@@ -249,7 +250,8 @@ static void setup_options(void)
/* open the app-specific key */ /* open the app-specific key */
if (GetModuleFileNameA( 0, buffer, MAX_PATH )) len = (GetModuleFileNameA( 0, buffer, MAX_PATH ));
if (len && len < MAX_PATH)
{ {
HKEY tmpkey; HKEY tmpkey;
char *p, *appname = buffer; char *p, *appname = buffer;
......
...@@ -531,8 +531,8 @@ static BOOL DeferToRunOnce(LPWSTR link) ...@@ -531,8 +531,8 @@ static BOOL DeferToRunOnce(LPWSTR link)
WINE_TRACE( "Deferring icon creation to reboot.\n"); WINE_TRACE( "Deferring icon creation to reboot.\n");
if( !GetModuleFileNameW( 0, szExecutable, MAX_PATH ) ) len = GetModuleFileNameW( 0, szExecutable, MAX_PATH );
return FALSE; if (!len || len >= MAX_PATH) return FALSE;
len = ( lstrlenW( link ) + lstrlenW( szExecutable ) + 4)*sizeof(WCHAR); len = ( lstrlenW( link ) + lstrlenW( szExecutable ) + 4)*sizeof(WCHAR);
buffer = HeapAlloc( GetProcessHeap(), 0, len ); buffer = HeapAlloc( GetProcessHeap(), 0, len );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment