Hans Leidekker : wininet: Don' t crash on NULL first or last parameter in InternetCrackUrlW.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Aug 10 07:31:07 CDT 2007


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

Author: Hans Leidekker <hans at it.vu.nl>
Date:   Thu Aug  9 18:33:41 2007 +0200

wininet: Don't crash on NULL first or last parameter in InternetCrackUrlW.

---

 dlls/wininet/internet.c  |    5 ++---
 dlls/wininet/tests/url.c |   13 +++++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index 36546b2..5e5bcea 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -1218,16 +1218,15 @@ BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWOR
     DWORD dwUrlLength = dwUrlLength_orig;
     const WCHAR lpszSeparators[3]={';','?',0};
     const WCHAR lpszSlash[2]={'/',0};
-    if(dwUrlLength==0)
-        dwUrlLength=strlenW(lpszUrl);
 
     TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
 
-    if (!lpszUrl_orig || !*lpszUrl_orig)
+    if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
     {
         INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
         return FALSE;
     }
+    if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
 
     if (dwFlags & ICU_DECODE)
     {
diff --git a/dlls/wininet/tests/url.c b/dlls/wininet/tests/url.c
index 98442bb..125e641 100644
--- a/dlls/wininet/tests/url.c
+++ b/dlls/wininet/tests/url.c
@@ -238,6 +238,7 @@ static void InternetCrackUrlW_test(void)
     static const WCHAR url2[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
     URL_COMPONENTSW comp;
     WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
+    DWORD error;
     BOOL r;
 
     urlpart[0]=0;
@@ -261,6 +262,18 @@ static void InternetCrackUrlW_test(void)
     comp.lpszExtraInfo = extra;
     comp.dwExtraInfoLength = sizeof extra;
 
+    SetLastError(0xdeadbeef);
+    r = InternetCrackUrlW(NULL, 0, 0, &comp );
+    error = GetLastError();
+    ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
+    ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
+
+    SetLastError(0xdeadbeef);
+    r = InternetCrackUrlW(url, 0, 0, NULL );
+    error = GetLastError();
+    ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
+    ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
+
     r = InternetCrackUrlW(url, 0, 0, &comp );
     ok( r, "failed to crack url\n");
     ok( comp.dwSchemeLength == 4, "scheme length wrong\n");




More information about the wine-cvs mailing list