Browse Source

win32: dirs: fix potential buffer overflow when appending "portable"

We let the concatenation decide if there's enough room or not.

And use the Wide char calls where wide char pointers are used.
pull/175/head
Steve Lhomme 1 year ago
parent
commit
28241fad50
  1. 17
      src/win32/dirs.c

17
src/win32/dirs.c

@ -120,16 +120,19 @@ static char *config_GetAppDir (void)
{
/* if portable directory exists, use it */
WCHAR path[MAX_PATH];
if (GetModuleFileName (NULL, path, MAX_PATH))
if (GetModuleFileNameW (NULL, path, MAX_PATH))
{
WCHAR *lastDir = wcsrchr (path, TEXT('\\'));
WCHAR *lastDir = wcsrchr (path, L'\\');
if (lastDir)
{
wcscpy (lastDir + 1, TEXT("portable"));
DWORD attrib = GetFileAttributes (path);
if (attrib != INVALID_FILE_ATTRIBUTES &&
(attrib & FILE_ATTRIBUTE_DIRECTORY))
return FromWide (path);
*lastDir = L'\0';
if (wcscat_s(path, ARRAY_SIZE(path), TEXT("\\portable")) == 0)
{
DWORD attrib = GetFileAttributesW (path);
if (attrib != INVALID_FILE_ATTRIBUTES &&
(attrib & FILE_ATTRIBUTE_DIRECTORY))
return FromWide (path);
}
}
}

Loading…
Cancel
Save