From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:59841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TFizN-0003vq-SB for qemu-devel@nongnu.org; Sun, 23 Sep 2012 06:00:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TFizM-0007cx-Mh for qemu-devel@nongnu.org; Sun, 23 Sep 2012 06:00:37 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:60030) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TFizM-0007UQ-G7 for qemu-devel@nongnu.org; Sun, 23 Sep 2012 06:00:36 -0400 Received: by mail-wi0-f169.google.com with SMTP id c10so129500wiw.4 for ; Sun, 23 Sep 2012 03:00:36 -0700 (PDT) From: Stefan Hajnoczi Date: Sun, 23 Sep 2012 11:00:11 +0100 Message-Id: <1348394420-28298-6-git-send-email-stefanha@gmail.com> In-Reply-To: <1348394420-28298-1-git-send-email-stefanha@gmail.com> References: <1348394420-28298-1-git-send-email-stefanha@gmail.com> Subject: [Qemu-devel] [PATCH 05/14] lm4549: Fix buffer overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Stefan Weil , qemu-devel@nongnu.org, Stefan Hajnoczi From: Stefan Weil Report from smatch: lm4549.c:234 lm4549_write_samples(14) error: buffer overflow 's->buffer' 1024 <= 1024 There must be enough space to add two entries starting with index s->buffer_level, therefore the old check was wrong. [Peter Maydell clarifies the nature of the analyser warning: I don't object to making the change to placate the analyser, but I don't think this is actually a buffer overrun. We always add and remove samples from the buffer two at a time, so it's not possible to get here with s->buffer_level == BUFFER_SIZE-1 (which is the only case where the old and new conditions give different answers).] Signed-off-by: Stefan Weil Signed-off-by: Stefan Hajnoczi --- hw/lm4549.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/lm4549.c b/hw/lm4549.c index 80b3ec4..e0137d5 100644 --- a/hw/lm4549.c +++ b/hw/lm4549.c @@ -224,7 +224,7 @@ uint32_t lm4549_write_samples(lm4549_state *s, uint32_t left, uint32_t right) This model supports 16-bit playback. */ - if (s->buffer_level >= LM4549_BUFFER_SIZE) { + if (s->buffer_level > LM4549_BUFFER_SIZE - 2) { DPRINTF("write_sample Buffer full\n"); return 0; } -- 1.7.10.4