OpenURL can cause nullpointer access
Original Reporter info from Mantis: hobbestherat
-
Reporter name: Thomas Frey
Original Reporter info from Mantis: hobbestherat
- Reporter name: Thomas Frey
Description:
sysenvapis_mac.inc :
does not check if the URL was created. So if the URL is not liked for whatever reasons, it causes a null access.
A fix could be to add
if not Assigned(url) then begin
CFRelease(cf);
Exit(False);
end;
after
url := CFURLCreateWithString(nil, cf, nil);
This would fix the nullpointer access, but it fails for me with URL containing "?" characters.
I suggest :
function OpenURL(AURL: String): Boolean;
var
url: CFURLRef;
begin
if url = '' then Exit(False);
url := CFURLCreateWithBytes(nil, @AURL[1], Length(AURL), kCFStringEncodingUTF8, nil);
if not Assigned(url) then Exit(False);
Result := LSOpenCFURLRef(url, nil) = 0;
CFRelease(url);
end;
This seems simpler to me and it works with for all my testcases. Before taking the code, please assure if Length(AURL) gives the byte length of the utf8 string.
Mantis conversion info:
- Mantis ID: 24958
- OS: OSX
- OS Build: 10.8.4
- Platform: Mac
- Monitored by: » hobbestherat (Thomas Frey)