Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined behaviour in get_num_outputs in CoreAudio driver #594

Merged
merged 1 commit into from
Nov 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/drivers/fluid_coreaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ get_num_outputs(AudioDeviceID deviceID)
pa.mScope = kAudioDevicePropertyScopeOutput;
pa.mElement = kAudioObjectPropertyElementMaster;

if(OK(AudioObjectGetPropertyDataSize(deviceID, &pa, 0, 0, &size)))
if(OK(AudioObjectGetPropertyDataSize(deviceID, &pa, 0, 0, &size)) && size > 0)
{
int num = size / (int) sizeof(AudioBufferList);
AudioBufferList bufList[num];
AudioBufferList *bufList = FLUID_MALLOC(size);

if(bufList == NULL)
{
FLUID_LOG(FLUID_ERR, "Out of memory");
return 0;
}

if(OK(AudioObjectGetPropertyData(deviceID, &pa, 0, 0, &size, bufList)))
{
Expand All @@ -98,6 +103,8 @@ get_num_outputs(AudioDeviceID deviceID)
total += b.mNumberChannels;
}
}

FLUID_FREE(bufList);
}

return total;
Expand Down