From ac0f957488ea0e8cfb32096b300f08f715aede06 Mon Sep 17 00:00:00 2001 From: Bryan Donlan Date: Sat, 26 Jan 2019 17:51:08 -0800 Subject: [PATCH] Fix NULL dereference in OnDefaultDeviceChanged When the vive pro wireless adapter loses connection, its audio devices are removed, causing an OnDefaultDeviceChanged event to be issued for each such device that was previously set as the default. However, if no other device is available for the role that was disconnected (e.g. if the Vive Pro was providing the only system microphone), then pwstrDefaultDeviceId is NULL. In this case, we would invoke getDevice on the NULL device ID, then attempt to print the default device name in the debug logging path; this NULL dereference would cause AdvancedSettings to crash. This change simply fixes the logging code to not attempt to print the new default device name when it is NULL. --- .../audiomanager/AudioManagerWindows.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/tabcontrollers/audiomanager/AudioManagerWindows.cpp b/src/tabcontrollers/audiomanager/AudioManagerWindows.cpp index 10e0f00..fc3947f 100644 --- a/src/tabcontrollers/audiomanager/AudioManagerWindows.cpp +++ b/src/tabcontrollers/audiomanager/AudioManagerWindows.cpp @@ -457,7 +457,7 @@ IMMDevice* LPCWSTR id ) { IMMDevice* pDevice; - if ( deviceEnumerator->GetDevice( id, &pDevice ) < 0 ) + if ( !id || deviceEnumerator->GetDevice( id, &pDevice ) < 0 ) { return nullptr; } @@ -606,6 +606,10 @@ AudioManagerWindows::OnDefaultDeviceChanged( EDataFlow flow, micAudioEndpointVolume = getAudioEndpointVolume( micAudioDevice ); } + else if ( !pwstrDefaultDeviceId ) + { + LOG( WARNING ) << "No recording device available."; + } else { std::wstring_convert> @@ -632,7 +636,11 @@ AudioManagerWindows::OnDefaultDeviceChanged( EDataFlow flow, playbackAudioDevice->Release(); } playbackAudioDevice = device; - if ( !playbackAudioDevice ) + if ( !pwstrDefaultDeviceId ) + { + LOG( WARNING ) << "No playback device available."; + } + else if ( !playbackAudioDevice ) { std::wstring_convert> converter;