From 45c8f4ebe4f9feb5a880fdaadaf1e6efce3eff46 Mon Sep 17 00:00:00 2001 From: wj32 Date: Mon, 25 Apr 2011 21:29:31 +0000 Subject: [PATCH] fixed bug in PhSetFileDialogFileName git-svn-id: svn://svn.code.sf.net/p/processhacker/code@4177 21ef857c-d57f-4fe0-8362-d861dc6d29cd --- 2.x/trunk/CHANGELOG.txt | 1 + 2.x/trunk/phlib/support.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/2.x/trunk/CHANGELOG.txt b/2.x/trunk/CHANGELOG.txt index 88b3daaee..905ee9c9f 100644 --- a/2.x/trunk/CHANGELOG.txt +++ b/2.x/trunk/CHANGELOG.txt @@ -8,6 +8,7 @@ Process Hacker * Image file versions * Workaround for an IPv6-related bug in Windows XP * DPCs and Interrupts in System Information tooltips + * File dialog crash on Windows XP 2.14 * NEW/IMPROVED: diff --git a/2.x/trunk/phlib/support.c b/2.x/trunk/phlib/support.c index e2c995e41..861ce7a4d 100644 --- a/2.x/trunk/phlib/support.c +++ b/2.x/trunk/phlib/support.c @@ -4177,6 +4177,7 @@ VOID PhSetFileDialogFileName( else { OPENFILENAME *ofn = (OPENFILENAME *)FileDialog; + SIZE_T length; if (wcschr(FileName, '/') || wcschr(FileName, '\"')) { @@ -4185,8 +4186,11 @@ VOID PhSetFileDialogFileName( } PhFree(ofn->lpstrFile); - ofn->nMaxFile = max((ULONG)wcslen(FileName) + 1, 0x400); - ofn->lpstrFile = PhAllocateCopy(FileName, ofn->nMaxFile * 2); + + length = wcslen(FileName); + ofn->nMaxFile = max(length + 1, 0x400); + ofn->lpstrFile = PhAllocate(ofn->nMaxFile * 2); + memcpy(ofn->lpstrFile, FileName, (length + 1) * 2); } }