[PATCH 3/3] wininet: Treat dwUrlLength as a maximum in InternetCrackUrlW

Tim Clem tclem at codeweavers.com
Thu Jul 1 12:40:04 CDT 2021


Signed-off-by: Tim Clem <tclem at codeweavers.com>
---
 dlls/wininet/internet.c  | 13 ++++++++++++-
 dlls/wininet/tests/url.c |  1 -
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index 1b6f060d607..c5b70e60d0c 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -1636,7 +1636,18 @@ BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwF
         SetLastError(ERROR_INVALID_PARAMETER);
         return FALSE;
     }
-    if (!dwUrlLength) dwUrlLength = lstrlenW(lpszUrl);
+
+    if (!dwUrlLength)
+        dwUrlLength = lstrlenW(lpszUrl);
+    else {
+        /* Windows stops at a null, regardless of what dwUrlLength says. */
+        DWORD len = wcsnlen(lpszUrl, dwUrlLength);
+        if (dwUrlLength != len) {
+            TRACE("dwUrlLength %u is past a null terminator. Treating length as %u.\n",
+                  dwUrlLength, len);
+            dwUrlLength = len;
+        }
+    }
 
     if (dwFlags & ICU_DECODE)
     {
diff --git a/dlls/wininet/tests/url.c b/dlls/wininet/tests/url.c
index 2f3ea9c3d14..c097a6f52f9 100644
--- a/dlls/wininet/tests/url.c
+++ b/dlls/wininet/tests/url.c
@@ -843,7 +843,6 @@ static void InternetCrackUrlW_test(void)
     comp.dwHostNameLength = ARRAY_SIZE(host);
     r = InternetCrackUrlW(url3, 13 /* includes the nul */, 0, &comp);
     ok(r, "InternetCrackUrlW failed with error %d\n", GetLastError());
-    todo_wine
     ok(comp.dwHostNameLength == 5,
         "Expected dwHostNameLength of 5, got %d\n", comp.dwHostNameLength);
 }
-- 
2.32.0




More information about the wine-devel mailing list