wininet: Fix HTTP_EncodeBasicAuth by passing an out buffer to the second set of character set conversion calls.

Robert Shearman rob at codeweavers.com
Tue Jan 16 14:44:54 CST 2007


---
  dlls/wininet/http.c |   16 ++++++++--------
  1 files changed, 8 insertions(+), 8 deletions(-)
-------------- next part --------------
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index ee41e3b..a737bfc 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -1127,10 +1127,10 @@ static LPWSTR HTTP_EncodeBasicAuth( LPCW
     char *in;
     LPWSTR out;
     static const WCHAR szBasic[] = {'B','a','s','i','c',' ',0};
-
-    len = WideCharToMultiByte(CP_UTF8, 0, username, lstrlenW(username), NULL, 0, NULL, NULL) +
-        1 + WideCharToMultiByte(CP_UTF8, 0, password, lstrlenW(password), NULL, 0, NULL, NULL);
-    in = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(CHAR) );
+    int userlen = WideCharToMultiByte(CP_UTF8, 0, username, lstrlenW(username), NULL, 0, NULL, NULL);
+    int passlen = WideCharToMultiByte(CP_UTF8, 0, password, lstrlenW(password), NULL, 0, NULL, NULL);
+    
+    in = HeapAlloc( GetProcessHeap(), 0, userlen + 1 + passlen );
     if( !in )
         return NULL;
 
@@ -1139,11 +1139,11 @@ static LPWSTR HTTP_EncodeBasicAuth( LPCW
     out = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
     if( out )
     {
-        WideCharToMultiByte(CP_UTF8, 0, username, -1, NULL, 0, NULL, NULL);
-        strcat(in, ":");
-        WideCharToMultiByte(CP_UTF8, 0, password, -1, NULL, 0, NULL, NULL);
+        WideCharToMultiByte(CP_UTF8, 0, username, -1, in, userlen, NULL, NULL);
+        in[userlen] = ':';
+        WideCharToMultiByte(CP_UTF8, 0, password, -1, &in[userlen+1], passlen, NULL, NULL);
         lstrcpyW( out, szBasic );
-        HTTP_EncodeBase64( in, len, &out[strlenW(out)] );
+        HTTP_EncodeBase64( in, userlen + 1 + passlen, &out[strlenW(out)] );
     }
     HeapFree( GetProcessHeap(), 0, in );
 


More information about the wine-patches mailing list