Commit ad57c70a authored by Alexander Nicolaysen Sørnes's avatar Alexander Nicolaysen Sørnes Committed by Alexandre Julliard

wordpad: Fix potential buffer overflow.

parent 4f14c470
...@@ -133,15 +133,28 @@ static WCHAR wszFileName[MAX_PATH]; ...@@ -133,15 +133,28 @@ static WCHAR wszFileName[MAX_PATH];
static void set_caption(LPCWSTR wszNewFileName) static void set_caption(LPCWSTR wszNewFileName)
{ {
static const WCHAR wszSeparator[] = {' ','-',' ','\0'}; static const WCHAR wszSeparator[] = {' ','-',' '};
WCHAR wszCaption[MAX_PATH];
if(wszNewFileName) if(wszNewFileName)
{ {
lstrcpyW(wszCaption, wszNewFileName); WCHAR *wszCaption;
lstrcatW(wszCaption, wszSeparator); SIZE_T length = 0;
lstrcatW(wszCaption, wszAppTitle);
wszCaption = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
lstrlenW(wszNewFileName)*sizeof(WCHAR)+sizeof(wszSeparator)+sizeof(wszAppTitle));
if(!wszCaption)
return;
memcpy(wszCaption, wszNewFileName, lstrlenW(wszNewFileName)*sizeof(WCHAR));
length += lstrlenW(wszNewFileName);
memcpy(wszCaption + length, wszSeparator, sizeof(wszSeparator));
length += sizeof(wszSeparator) / sizeof(WCHAR);
memcpy(wszCaption + length, wszAppTitle, sizeof(wszAppTitle));
SetWindowTextW(hMainWnd, wszCaption); SetWindowTextW(hMainWnd, wszCaption);
HeapFree(GetProcessHeap(), 0, wszCaption);
} else } else
{ {
SetWindowTextW(hMainWnd, wszAppTitle); SetWindowTextW(hMainWnd, wszAppTitle);
......
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