--- old/src/java.base/macosx/native/libnet/DefaultProxySelector.c 2017-01-31 11:35:51.000000000 +0000 +++ new/src/java.base/macosx/native/libnet/DefaultProxySelector.c 2017-01-31 11:35:50.000000000 +0000 @@ -61,8 +61,10 @@ } /* - * This will resolve all PAC URLs in the given array and return an array containing no more - * PAC URLs. + * Returns a new array of proxies containing all the given non-PAC proxies as + * well as the results of executing all the given PAC-based proxies, for the + * specified URL. 'proxies' is a list that may contain both PAC and non-PAC + * proxies. */ static CFArrayRef createExpandedProxiesArray(CFArrayRef proxies, CFURLRef url) { @@ -71,7 +73,8 @@ CFMutableArrayRef expandedProxiesArray; expandedProxiesArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); - assert(expandedProxiesArray != NULL); + if (expandedProxiesArray == NULL) + return NULL; /* Iterate over the array of proxies */ count = CFArrayGetCount(proxies); @@ -80,15 +83,21 @@ CFStringRef proxyType; currentProxy = (CFDictionaryRef) CFArrayGetValueAtIndex(proxies, index); - assert(currentProxy != NULL); + if(currentProxy == NULL) { + CFRelease(expandedProxiesArray); + return NULL; + } proxyType = (CFStringRef) CFDictionaryGetValue(currentProxy, kCFProxyTypeKey); - assert(proxyType != NULL); + if (proxyType == NULL) { + CFRelease(expandedProxiesArray); + return NULL; + } if (!CFEqual(proxyType, kCFProxyTypeAutoConfigurationURL)) { - /* This is a non PAC entry - just copy it to the new array. */ + /* Non-PAC entry, just copy it to the new array */ CFArrayAppendValue(expandedProxiesArray, currentProxy); } else { - /* This is a PAC URL and we have to resolve it. */ + /* PAC-based URL, execute its script append its results */ CFRunLoopSourceRef runLoop; CFURLRef scriptURL; CFTypeRef result = NULL; @@ -109,14 +118,14 @@ CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runLoop, kResolveProxyRunLoopMode); /* - * Once the runloop returns, we should have either an error result or a - * proxies array result. Do the appropriate thing with that result. + * Once the runloop returns, there will be either an error result or + * a proxies array result. Do the appropriate thing with that result. */ if (result != NULL) { if (CFGetTypeID(result) == CFArrayGetTypeID()) { /* - * Append the new array from the PAC list - it does - * contain no more PAC URIs. + * Append the new array from the PAC list - it contains + * only non-PAC entries. */ CFArrayAppendArray(expandedProxiesArray, result, CFRangeMake(0, CFArrayGetCount(result))); @@ -205,6 +214,12 @@ CFArrayRef expandedProxyArray = createExpandedProxiesArray(urlProxyArrayRef, urlRef); CFRelease(urlProxyArrayRef); + if (expandedProxyArray == NULL) { + CFRelease(urlRef); + CFRelease(proxyDicRef); + return NULL; + } + count = CFArrayGetCount(expandedProxyArray); proxyArray = (*env)->NewObjectArray(env, count, proxy_class, NULL); @@ -219,15 +234,12 @@ index); proxyType = (CFStringRef) CFDictionaryGetValue(currentProxy, kCFProxyTypeKey); if (CFEqual(proxyType, kCFProxyTypeNone)) { - /* - * This entry states we should use no proxy - therefor we just create a - * NO_PROXY object. - */ + /* This entry states no proxy, therefore just add a NO_PROXY object. */ proxy = (*env)->GetStaticObjectField(env, proxy_class, pr_no_proxyID); } else { /* - * Create a proxy object for this entry. We have to differentiate between - * socks and http type. + * Create a proxy object for this entry. + * Differentiate between SOCKS and HTTP type. */ jfieldID typeID = ptype_httpID; if (CFEqual(proxyType, kCFProxyTypeSOCKS)) {