Alexandre Julliard : shlwapi: Fix GetAcceptLanguagesA to not read past the end of the buffer.

Alexandre Julliard julliard at winehq.org
Tue Oct 2 06:52:37 CDT 2007


Module: wine
Branch: master
Commit: 3ee3058677d4d3be4c18e3bd81bab3d956e4a49b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3ee3058677d4d3be4c18e3bd81bab3d956e4a49b

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Oct  1 18:09:11 2007 +0200

shlwapi: Fix GetAcceptLanguagesA to not read past the end of the buffer.

---

 dlls/shlwapi/ordinal.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/dlls/shlwapi/ordinal.c b/dlls/shlwapi/ordinal.c
index b1cb585..d3e5825 100644
--- a/dlls/shlwapi/ordinal.c
+++ b/dlls/shlwapi/ordinal.c
@@ -529,9 +529,15 @@ HRESULT WINAPI GetAcceptLanguagesA( LPSTR langbuf, LPDWORD buflen)
     langbufW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * buflenW);
     retval = GetAcceptLanguagesW(langbufW, &buflenW);
 
-    /* FIXME: this is wrong, the string may not be null-terminated */
-    convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, -1, langbuf,
-                                  *buflen, NULL, NULL);
+    if (retval == S_OK)
+    {
+        convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, -1, langbuf, *buflen, NULL, NULL);
+    }
+    else  /* copy partial string anyway */
+    {
+        convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, *buflen, langbuf, *buflen, NULL, NULL);
+        if (convlen < *buflen) langbuf[convlen] = 0;
+    }
     *buflen = buflenW ? convlen : 0;
 
     HeapFree(GetProcessHeap(), 0, langbufW);




More information about the wine-cvs mailing list