From patchwork Sun Sep 23 10:00:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 186195 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 71B682C0092 for ; Sun, 23 Sep 2012 20:14:24 +1000 (EST) Received: from localhost ([::1]:46615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TFizz-0005ZC-9j for incoming@patchwork.ozlabs.org; Sun, 23 Sep 2012 06:01:15 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=5zyvXwoFDirowBH8Fej/jWLHLXWOBQrCopFnDsFHpbM=; b=ROeKADjHaKWFiW24QYl5q2e2Dk+qi2xTVLg7J4hwUDryqZmvK8Fy+lnYB/nd0FmAXj OKgK/OIx/YZcWI7yi8MnpTGUfQaJcevfIQvDOxibNZ3xaNtmIpNg6KJhKzrPstud+SH3 HBhmG5V95ZlAIgbBoVJfzfTxS6flYC7sUGYjXOtxsl5DaQNNlH0aX9ubblCGedkpAG2I flcEPgTRLabqCfJSSk9/UbpnKzBqg+38QsweAJ5ENoG4H2q/LkRWUPOoTSEiBXz4D3OD /5OPv8xpPisDZozocnUugoiMUHxWZDO39yLVnU1jADit3MuBUpNWdXbKpd6IU6GK7E78 Mv4Q== Received: by 10.180.94.38 with SMTP id cz6mr7609204wib.10.1348394436049; Sun, 23 Sep 2012 03:00:36 -0700 (PDT) Received: from localhost ([109.224.133.37]) by mx.google.com with ESMTPS id l5sm9493418wix.5.2012.09.23.03.00.35 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 23 Sep 2012 03:00:35 -0700 (PDT) From: Stefan Hajnoczi To: Anthony Liguori Date: Sun, 23 Sep 2012 11:00:11 +0100 Message-Id: <1348394420-28298-6-git-send-email-stefanha@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1348394420-28298-1-git-send-email-stefanha@gmail.com> References: <1348394420-28298-1-git-send-email-stefanha@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.212.169 Cc: Stefan Weil , qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 05/14] lm4549: Fix buffer overflow X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; }