On Tue, Nov 10, 2026 at 12:31 PM Manos Pitsidianakis <[email protected]> wrote: > > 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 > Signed-off-by: Manos Pitsidianakis <[email protected]> > --- > hw/audio/virtio-snd.c | 24 +++++++++++++++--------- > 1 file changed, 15 insertions(+), 9 deletions(-) > > diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c > index 8695a4651b..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; > @@ -352,15 +357,16 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s, > return cpu_to_le32(VIRTIO_SND_S_NOT_SUPP); > } > if ((le32_to_cpu(params->features) & ~(stream->info.features)) > 0) { > - error_report("%s: invalid stream features. " > - "Stream %d offers 0x%"PRIx32", " > - "guest requested 0x%"PRIx32 > - " (invalid: 0x%"PRIx32")", > - VIRTIO_DEVICE(s)->name, stream_id, > - stream->info.features, > - le32_to_cpu(params->features), > - le32_to_cpu(params->features) & ~(stream->info.features)); > - return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); > + error_report("%s: invalid stream features. " > + "Stream %d offers 0x%"PRIx32", " > + "guest requested 0x%"PRIx32 > + " (invalid: 0x%"PRIx32")", > + VIRTIO_DEVICE(s)->name, stream_id, > + stream->info.features, > + le32_to_cpu(params->features), > + le32_to_cpu(params->features) > + & ~(stream->info.features)); > + return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
Squashed the fixup to the wrong commit... sent a v2 fixing this. > } > > st_params = virtio_snd_pcm_get_params(s, stream_id); > > -- > 2.56.0 >
