forked from len0rd/rockbox
Fix crash on proxy detection on OS X (FS#11654).
If the proxy dialog doesn't contain any values searching for the values in the system returns NULL pointers instead of empty values. Check for them to fix crashes. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28212 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
85f1df1b1a
commit
90e8815673
1 changed files with 26 additions and 19 deletions
|
|
@ -509,33 +509,40 @@ QUrl System::systemProxy(void)
|
||||||
CFDictionaryRef dictref;
|
CFDictionaryRef dictref;
|
||||||
CFStringRef stringref;
|
CFStringRef stringref;
|
||||||
CFNumberRef numberref;
|
CFNumberRef numberref;
|
||||||
int enable;
|
int enable = 0;
|
||||||
int port;
|
int port = 0;
|
||||||
unsigned int bufsize = 0;
|
unsigned int bufsize = 0;
|
||||||
char *buf;
|
char *buf;
|
||||||
QUrl proxy;
|
QUrl proxy;
|
||||||
|
|
||||||
dictref = SCDynamicStoreCopyProxies(NULL);
|
dictref = SCDynamicStoreCopyProxies(NULL);
|
||||||
stringref = (CFStringRef)CFDictionaryGetValue(dictref, kSCPropNetProxiesHTTPProxy);
|
if(dictref == NULL)
|
||||||
|
return proxy;
|
||||||
numberref = (CFNumberRef)CFDictionaryGetValue(dictref, kSCPropNetProxiesHTTPEnable);
|
numberref = (CFNumberRef)CFDictionaryGetValue(dictref, kSCPropNetProxiesHTTPEnable);
|
||||||
CFNumberGetValue(numberref, kCFNumberIntType, &enable);
|
if(numberref != NULL)
|
||||||
|
CFNumberGetValue(numberref, kCFNumberIntType, &enable);
|
||||||
if(enable == 1) {
|
if(enable == 1) {
|
||||||
// get number of characters. CFStringGetLength uses UTF-16 code pairs
|
// get proxy string
|
||||||
bufsize = CFStringGetLength(stringref) * 2 + 1;
|
stringref = (CFStringRef)CFDictionaryGetValue(dictref, kSCPropNetProxiesHTTPProxy);
|
||||||
buf = (char*)malloc(sizeof(char) * bufsize);
|
if(stringref != NULL) {
|
||||||
if(buf == NULL) {
|
// get number of characters. CFStringGetLength uses UTF-16 code pairs
|
||||||
qDebug() << "[System] can't allocate memory for proxy string!";
|
bufsize = CFStringGetLength(stringref) * 2 + 1;
|
||||||
CFRelease(dictref);
|
buf = (char*)malloc(sizeof(char) * bufsize);
|
||||||
return QUrl("");
|
if(buf == NULL) {
|
||||||
}
|
qDebug() << "[System] can't allocate memory for proxy string!";
|
||||||
CFStringGetCString(stringref, buf, bufsize, kCFStringEncodingUTF16);
|
CFRelease(dictref);
|
||||||
numberref = (CFNumberRef)CFDictionaryGetValue(dictref, kSCPropNetProxiesHTTPPort);
|
return QUrl("");
|
||||||
CFNumberGetValue(numberref, kCFNumberIntType, &port);
|
}
|
||||||
proxy.setScheme("http");
|
CFStringGetCString(stringref, buf, bufsize, kCFStringEncodingUTF16);
|
||||||
proxy.setHost(QString::fromUtf16((unsigned short*)buf));
|
numberref = (CFNumberRef)CFDictionaryGetValue(dictref, kSCPropNetProxiesHTTPPort);
|
||||||
proxy.setPort(port);
|
if(numberref != NULL)
|
||||||
|
CFNumberGetValue(numberref, kCFNumberIntType, &port);
|
||||||
|
proxy.setScheme("http");
|
||||||
|
proxy.setHost(QString::fromUtf16((unsigned short*)buf));
|
||||||
|
proxy.setPort(port);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CFRelease(dictref);
|
CFRelease(dictref);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue