From: Alexander Mikhalitsyn <[email protected]>
Coverity suspects nullptr-deref, because we don't check a return value
of virtio_snd_pcm_get_stream() call in virtio_snd_post_load().
While, techically this code has no issue it's better to change it and
as Peter has pointed out [1] just follow the same pattern as in other places
of virtio-snd code:
for (uint32_t i = 0; i < vsnd->snd_conf.streams; i++) {
VirtIOSoundPCMStream *stream = &vsnd->streams[i];
...
}
this way it's perfectly clear that an index is always within the bounds.
Link:
https://lore.kernel.org/qemu-devel/cafeaca-k7l5nwk0cc9r8yvvojss6o6eh+i9kxp8lijo4tjn...@mail.gmail.com
[1]
Resolves: Coverity CID 1687010
Reported-by: Peter Maydell <[email protected]>
Signed-off-by: Alexander Mikhalitsyn <[email protected]>
---
hw/audio/virtio-snd.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index 6df7ea0eb0..fb22d79949 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -1448,9 +1448,8 @@ static int virtio_snd_post_load(VirtIODevice *vdev)
uint32_t i;
for (i = 0; i < s->snd_conf.streams; i++) {
- struct VirtIOSoundPCMStream *stream;
+ VirtIOSoundPCMStream *stream = &s->streams[i];
- stream = virtio_snd_pcm_get_stream(s, i);
if (virtio_snd_pcm_state_prepared(stream->state)) {
virtio_snd_pcm_open(stream);
--
2.47.3