]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
hw/audio/asc: fix SIGSEGV in asc_realize()
authorVolker Rümelin <vr_qemu@t-online.de>
Thu, 15 May 2025 05:44:26 +0000 (07:44 +0200)
committerMichael Tokarev <mjt@tls.msk.ru>
Thu, 5 Jun 2025 12:10:42 +0000 (15:10 +0300)
AUD_open_out() may fail and return NULL. This may then lead to
a segmentation fault in memset() below. The memset() behaviour
is undefined if the pointer to the destination object is a null
pointer.

Add the missing error handling code.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-Id: <20250515054429.7385-4-vr_qemu@t-online.de>
(cherry picked from commit d009f26a54f573468be721590a19350c224bc730)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
hw/audio/asc.c

index cc205bf063ed0d3436d51bc067876cfb2aa218f3..b7d0fd8acdeb751a01f29cf4dfeba55f556c8ff7 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/timer.h"
+#include "qapi/error.h"
 #include "hw/sysbus.h"
 #include "hw/irq.h"
 #include "audio/audio.h"
@@ -654,6 +655,12 @@ static void asc_realize(DeviceState *dev, Error **errp)
 
     s->voice = AUD_open_out(&s->card, s->voice, "asc.out", s, asc_out_cb,
                             &as);
+    if (!s->voice) {
+        AUD_remove_card(&s->card);
+        error_setg(errp, "Initializing audio stream failed");
+        return;
+    }
+
     s->shift = 1;
     s->samples = AUD_get_buffer_size_out(s->voice) >> s->shift;
     s->mixbuf = g_malloc0(s->samples << s->shift);