From 76b25a1377397fcde71920f2a78d30615bf055fd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 14 Oct 2022 23:14:08 +0200 Subject: [PATCH] output/alsa: add nullptr check for snd_pcm_name() return value It is not explicitly documented whether snd_pcm_name() is allowed to return NULL: https://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.html#ga5031edc0422df8db1f70af056a12dd77 But apparently this is legal: https://github.com/alsa-project/alsa-lib/blob/0222f45d11e8b71bf651b985b00fdb0addbf3eed/src/pcm/pcm.c#L2761-L2762 That's ... surprising! Closes https://github.com/MusicPlayerDaemon/MPD/issues/1645 --- NEWS | 2 ++ src/output/plugins/AlsaOutputPlugin.cxx | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 68729891e..4052ebe41 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ ver 0.23.10 (not yet released) - ffmpeg: fix libfmt 9 compiler warning * encoder - flac: fix failure when libFLAC is built without Ogg support +* output + - alsa: fix crash bug * Windows - log to stdout by default, don't require "log_file" setting diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index eebd47540..19e57b4dd 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -812,8 +812,12 @@ AlsaOutput::Open(AudioFormat &audio_format) fmt::format("Failed to open ALSA device \"{}\"", GetDevice()).c_str()); + const char *pcm_name = snd_pcm_name(pcm); + if (pcm_name == nullptr) + pcm_name = "?"; + FmtDebug(alsa_output_domain, "opened {} type={}", - snd_pcm_name(pcm), + pcm_name, snd_pcm_type_name(snd_pcm_type(pcm))); #ifdef ENABLE_DSD