[PATCH] wininet: Avoid passing NULL to heap_strdupW()

Michael Stefaniuc mstefani at winehq.org
Mon Feb 12 14:20:11 CST 2018


---
Without sign off as I don't like this patch.



 dlls/wininet/internet.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index 699962c1b0..4d054703e1 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -1047,12 +1047,12 @@ HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
     lpwai->proxyPassword = NULL;
     lpwai->connect_timeout = connect_timeout;
 
-    lpwai->agent = heap_strdupW(lpszAgent);
+    lpwai->agent = lpszAgent ? heap_strdupW(lpszAgent) : NULL;
     if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
         INTERNET_ConfigureProxy( lpwai );
     else if(dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
         lpwai->proxy = heap_strdupW(lpszProxy);
-        lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
+        lpwai->proxyBypass = lpszProxyBypass ? heap_strdupW(lpszProxyBypass) : NULL;
     }
 
     TRACE("returning %p\n", lpwai);
@@ -2431,14 +2431,18 @@ static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL u
                 break;
 
             case INTERNET_PER_CONN_PROXY_SERVER:
-                if (unicode)
+                if (!pi.proxy)
+                    optionW->Value.pszValue = NULL;
+                else if (unicode)
                     optionW->Value.pszValue = heap_strdupW(pi.proxy);
                 else
                     optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
                 break;
 
             case INTERNET_PER_CONN_PROXY_BYPASS:
-                if (unicode)
+                if (!pi.proxyBypass)
+                    optionW->Value.pszValue = NULL;
+                else if (unicode)
                     optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
                 else
                     optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
@@ -2750,8 +2754,8 @@ BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
                 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
                 {
                     global_proxy->proxyEnabled = 1;
-                    global_proxy->proxy = heap_strdupW( info->lpszProxy );
-                    global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
+                    global_proxy->proxy = info->lpszProxy ? heap_strdupW( info->lpszProxy ) : NULL;
+                    global_proxy->proxyBypass = info->lpszProxyBypass ? heap_strdupW( info->lpszProxyBypass ) : NULL;
                 }
                 else
                 {
@@ -2894,7 +2898,7 @@ BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
             switch (option->dwOption) {
             case INTERNET_PER_CONN_PROXY_SERVER:
                 heap_free(pi.proxy);
-                pi.proxy = heap_strdupW(option->Value.pszValue);
+                pi.proxy = option->Value.pszValue ? heap_strdupW(option->Value.pszValue) : NULL;
                 break;
 
             case INTERNET_PER_CONN_FLAGS:
@@ -2910,7 +2914,7 @@ BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
 
             case INTERNET_PER_CONN_PROXY_BYPASS:
                 heap_free(pi.proxyBypass);
-                pi.proxyBypass = heap_strdupW(option->Value.pszValue);
+                pi.proxyBypass = option->Value.pszValue ? heap_strdupW(option->Value.pszValue) : NULL;
                 break;
 
             case INTERNET_PER_CONN_AUTOCONFIG_URL:
@@ -3591,7 +3595,7 @@ HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
 
         task = alloc_async_task(&hIC->hdr, AsyncInternetOpenUrlProc, sizeof(*task));
         task->url = heap_strdupW(lpszUrl);
-        task->headers = heap_strdupW(lpszHeaders);
+        task->headers = lpszHeaders ? heap_strdupW(lpszHeaders) : NULL;
         task->headers_len = dwHeadersLength;
         task->flags = dwFlags;
         task->context = dwContext;
-- 
2.14.3




More information about the wine-devel mailing list