From patchwork Fri Jul 31 14:21:01 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: roel kluin X-Patchwork-Id: 30431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 10F7DB7BAE for ; Sat, 1 Aug 2009 00:19:31 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1MWsvz-0001tR-0l; Fri, 31 Jul 2009 14:18:11 +0000 Received: from mail-ew0-f211.google.com ([209.85.219.211]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1MWsvp-0001hw-FL for linux-mtd@lists.infradead.org; Fri, 31 Jul 2009 14:18:08 +0000 Received: by ewy7 with SMTP id 7so1119666ewy.18 for ; Fri, 31 Jul 2009 07:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=AvrNRU88cJgRKgqoeNQaLuVmjXK5Sis6qkqf+qk2axs=; b=rQCSpGXbduQh65pqXKX5jVVCM7VdAQxb5JGlZDvi4DlP62neBEuwi2aueMD/PTAQqR 9Gr0mbGbc6reB4P0mbgqxGVlB2HPuNbUJKT85xADMC13NmGhilc5sZbQ0x6g5G5YJZUV TdZY64NjulHutkGYXIxPc0robbO9qJ7zVmR3A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=s8DrZAQVABM5LMeX6FsbeREYH+vjL3iT16x3cWkScZsGjcgCgctAg9G/QMMRZ/eKKC cKW+nNEMJSKtotjybbZzIJnlRMErJazPRYocaVXgOF3Lbzs+at7mI165tUL+O3I2mxOF 6tmw/DVcZeT85+PwvB3a4uH/V8ZCTxUkpjOnM= Received: by 10.216.3.195 with SMTP id 45mr30520weh.8.1249049878894; Fri, 31 Jul 2009 07:17:58 -0700 (PDT) Received: from zoinx.mars (d133062.upc-d.chello.nl [213.46.133.62]) by mx.google.com with ESMTPS id 5sm3177484eyf.28.2009.07.31.07.17.57 (version=SSLv3 cipher=RC4-MD5); Fri, 31 Jul 2009 07:17:58 -0700 (PDT) Message-ID: <4A72FDCD.1070109@gmail.com> Date: Fri, 31 Jul 2009 16:21:01 +0200 From: Roel Kluin User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Thunderbird/3.0b2 MIME-Version: 1.0 To: dwmw2@infradead.org, linux-mtd@lists.infradead.org, Andrew Morton Subject: [PATCH] MTD: Read buffer overflow X-Spam-Score: 0.0 (/) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Check whether index is within bounds before testing the element. Signed-off-by: Roel Kluin --- with `for (i = 0; bbt[i] && i < ebcnt; ++i)' we test bbt[ebcnt] in the last iteration with `for (i = 0; bbt[ebcnt - i - 1] && i < ebcnt; ++i)' we test bbt[-1] in the last iteration diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c index a18e8d2..5553cd4 100644 --- a/drivers/mtd/tests/mtd_oobtest.c +++ b/drivers/mtd/tests/mtd_oobtest.c @@ -512,7 +512,7 @@ static int __init mtd_oobtest_init(void) goto out; addr0 = 0; - for (i = 0; bbt[i] && i < ebcnt; ++i) + for (i = 0; i < ebcnt && bbt[i]; ++i) addr0 += mtd->erasesize; /* Attempt to write off end of OOB */ diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c index 9648818..103cac4 100644 --- a/drivers/mtd/tests/mtd_pagetest.c +++ b/drivers/mtd/tests/mtd_pagetest.c @@ -116,11 +116,11 @@ static int verify_eraseblock(int ebnum) loff_t addr = ebnum * mtd->erasesize; addr0 = 0; - for (i = 0; bbt[i] && i < ebcnt; ++i) + for (i = 0; i < ebcnt && bbt[i]; ++i) addr0 += mtd->erasesize; addrn = mtd->size; - for (i = 0; bbt[ebcnt - i - 1] && i < ebcnt; ++i) + for (i = 0; i < ebcnt && bbt[ebcnt - i - 1]; ++i) addrn -= mtd->erasesize; set_random_data(writebuf, mtd->erasesize); @@ -219,11 +219,11 @@ static int crosstest(void) memset(pp1, 0, pgsize * 4); addr0 = 0; - for (i = 0; bbt[i] && i < ebcnt; ++i) + for (i = 0; i < ebcnt && bbt[i]; ++i) addr0 += mtd->erasesize; addrn = mtd->size; - for (i = 0; bbt[ebcnt - i - 1] && i < ebcnt; ++i) + for (i = 0; i < ebcnt && bbt[ebcnt - i - 1]; ++i) addrn -= mtd->erasesize; /* Read 2nd-to-last page to pp1 */ @@ -317,7 +317,7 @@ static int erasecrosstest(void) ebnum = 0; addr0 = 0; - for (i = 0; bbt[i] && i < ebcnt; ++i) { + for (i = 0; i < ebcnt && bbt[i]; ++i) { addr0 += mtd->erasesize; ebnum += 1; } @@ -413,7 +413,7 @@ static int erasetest(void) ebnum = 0; addr0 = 0; - for (i = 0; bbt[i] && i < ebcnt; ++i) { + for (i = 0; i < ebcnt && bbt[i]; ++i) { addr0 += mtd->erasesize; ebnum += 1; }