Fix AppleMIDI crash when deviceName or endPointName is null (#5729)

This commit is contained in:
Frank Lyder
2020-10-30 02:57:15 +01:00
committed by GitHub
parent c23c1b79d5
commit ec2e854a47

View File

@@ -401,9 +401,9 @@ void MidiApple::midiInClose( MIDIEndpointRef reference )
char *getName( MIDIObjectRef &object )
{
// Returns the name of a given MIDIObjectRef as char *
CFStringRef name = nil;
CFStringRef name = nullptr;
if (noErr != MIDIObjectGetStringProperty(object, kMIDIPropertyName, &name))
return nil;
return nullptr;
int len = CFStringGetLength(name)+1;
char *value = (char *) malloc(len);
@@ -615,8 +615,12 @@ char * MidiApple::getFullName(MIDIEndpointRef &endpoint_ref)
char * deviceName = getName(device);
char * endPointName = getName(endpoint_ref);
qDebug("device name='%s' endpoint name='%s'",deviceName,endPointName);
char * fullName = (char *)malloc(strlen(deviceName) + strlen(":") + strlen(endPointName)+1);
size_t deviceNameLen = deviceName == nullptr ? 0 : strlen(deviceName);
size_t endPointNameLen = endPointName == nullptr ? 0 : strlen(endPointName);
char * fullName = (char *)malloc(deviceNameLen + endPointNameLen + 2);
sprintf(fullName, "%s:%s", deviceName,endPointName);
if (deviceName != nullptr) { free(deviceName); }
if (endPointName != nullptr) { free(endPointName); }
return fullName;
}