Nikolay Sivov : mshtml: Make sure actual host length matches returned BSTR length.

Alexandre Julliard julliard at winehq.org
Wed Nov 22 16:12:02 CST 2017


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

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed Nov 22 17:55:07 2017 +0300

mshtml: Make sure actual host length matches returned BSTR length.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mshtml/htmllocation.c       | 7 +++++--
 dlls/mshtml/tests/htmllocation.c | 7 ++++++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/dlls/mshtml/htmllocation.c b/dlls/mshtml/htmllocation.c
index de66ff5..59b20f6 100644
--- a/dlls/mshtml/htmllocation.c
+++ b/dlls/mshtml/htmllocation.c
@@ -351,13 +351,16 @@ static HRESULT WINAPI HTMLLocation_get_host(IHTMLLocation *iface, BSTR *p)
     if(url.nPort) {
         /* <hostname>:<port> */
         const WCHAR format[] = {'%','u',0};
-        DWORD len = url.dwHostNameLength + 1 + 5;
+        DWORD len, port_len;
+        WCHAR portW[6];
         WCHAR *buf;
 
+        port_len = snprintfW(portW, sizeof(portW)/sizeof(portW[0]), format, url.nPort);
+        len = url.dwHostNameLength + 1 /* ':' */ + port_len;
         buf = *p = SysAllocStringLen(NULL, len);
         memcpy(buf, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
         buf[url.dwHostNameLength] = ':';
-        snprintfW(buf + url.dwHostNameLength + 1, 6, format, url.nPort);
+        memcpy(buf + url.dwHostNameLength + 1, portW, port_len * sizeof(WCHAR));
     }else
         *p = SysAllocStringLen(url.lpszHostName, url.dwHostNameLength);
 
diff --git a/dlls/mshtml/tests/htmllocation.c b/dlls/mshtml/tests/htmllocation.c
index ee241e7..458960a 100644
--- a/dlls/mshtml/tests/htmllocation.c
+++ b/dlls/mshtml/tests/htmllocation.c
@@ -168,10 +168,15 @@ static void test_host(IHTMLLocation *loc, const struct location_test *test)
 
     hres = IHTMLLocation_get_host(loc, &str);
     ok(hres == S_OK, "%s: get_host failed: 0x%08x\n", test->name, hres);
-    if(hres == S_OK)
+    if(hres == S_OK){
+        int len = test->host ? strlen(test->host) : 0;
         ok(str_eq_wa(str, test->host),
                 "%s: expected retrieved host to be L\"%s\", was: %s\n",
                 test->name, test->host, wine_dbgstr_w(str));
+        ok(SysStringLen(str) == len, "%s: unexpected string length %u, expected %u\n",
+                test->name, SysStringLen(str), len);
+    }
+
     SysFreeString(str);
 }
 




More information about the wine-cvs mailing list