Commit 0d9843799c for qemu.org
commit 0d9843799c7e2485458b419b6cd3159809dcc9fc
Author: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Date: Tue Nov 10 12:04:28 2026 +0200
virtio-snd: don't allocate pcm_info zero-count buf
g_new0() might return NULL, which is UB if passed to a memcpy
implementation that does not expect it (not in the usual case).
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3778
Reviewed-by: Jim MacArthur <jim.macarthur@linaro.org>
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index 89406f0a3a..a7d749f24f 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -267,6 +267,11 @@ static void virtio_snd_handle_pcm_info(VirtIOSound *s,
return;
}
+ if (count == 0) {
+ cmd->payload_size = 0;
+ cmd->resp.code = cpu_to_le32(VIRTIO_SND_S_OK);
+ return;
+ }
pcm_info = g_new0(virtio_snd_pcm_info, count);
for (uint32_t i = 0; i < count; i++) {
stream_id = i + start_id;