dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0220-lm4549-Fix-buffer-overflow.patch

5544c1
From 00338325c4a2c5b0010462b21a4373cbb4341c9d Mon Sep 17 00:00:00 2001
5544c1
From: Stefan Weil <sw@weilnetz.de>
5544c1
Date: Sat, 1 Sep 2012 12:43:41 +0200
5544c1
Subject: [PATCH] lm4549: Fix buffer overflow
5544c1
5544c1
Report from smatch:
5544c1
lm4549.c:234 lm4549_write_samples(14) error:
5544c1
 buffer overflow 's->buffer' 1024 <= 1024
5544c1
5544c1
There must be enough space to add two entries starting with index
5544c1
s->buffer_level, therefore the old check was wrong.
5544c1
5544c1
[Peter Maydell <peter.maydell@linaro.org> clarifies the nature of the
5544c1
analyser warning:
5544c1
5544c1
I don't object to making the change to placate the analyser,
5544c1
but I don't think this is actually a buffer overrun. We always
5544c1
add and remove samples from the buffer two at a time, so it's
5544c1
not possible to get here with s->buffer_level == BUFFER_SIZE-1
5544c1
(which is the only case where the old and new conditions
5544c1
give different answers).]
5544c1
5544c1
Signed-off-by: Stefan Weil <sw@weilnetz.de>
5544c1
Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
5544c1
(cherry picked from commit 8139626643cbe8dc07bd9acc88057effeedf8064)
5544c1
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 hw/lm4549.c | 2 +-
5544c1
 1 file changed, 1 insertion(+), 1 deletion(-)
5544c1
5544c1
diff --git a/hw/lm4549.c b/hw/lm4549.c
5544c1
index 80b3ec4..e0137d5 100644
5544c1
--- a/hw/lm4549.c
5544c1
+++ b/hw/lm4549.c
5544c1
@@ -224,7 +224,7 @@ uint32_t lm4549_write_samples(lm4549_state *s, uint32_t left, uint32_t right)
5544c1
        This model supports 16-bit playback.
5544c1
     */
5544c1
 
5544c1
-    if (s->buffer_level >= LM4549_BUFFER_SIZE) {
5544c1
+    if (s->buffer_level > LM4549_BUFFER_SIZE - 2) {
5544c1
         DPRINTF("write_sample Buffer full\n");
5544c1
         return 0;
5544c1
     }
5544c1
-- 
5544c1
1.7.12.1
5544c1