public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [patch 7/8] mtd: fix read buffer overflow
@ 2009-08-06 23:05 akpm
  2009-08-10  7:07 ` Artem Bityutskiy
  2009-08-10  7:13 ` Artem Bityutskiy
  0 siblings, 2 replies; 3+ messages in thread
From: akpm @ 2009-08-06 23:05 UTC (permalink / raw)
  To: dwmw2; +Cc: roel.kluin, akpm, linux-mtd

From: Roel Kluin <roel.kluin@gmail.com>

Check whether index is within bounds before testing the element.

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

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/mtd/tests/mtd_oobtest.c  |    2 +-
 drivers/mtd/tests/mtd_pagetest.c |   12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff -puN drivers/mtd/tests/mtd_oobtest.c~mtd-fix-read-buffer-overflow drivers/mtd/tests/mtd_oobtest.c
--- a/drivers/mtd/tests/mtd_oobtest.c~mtd-fix-read-buffer-overflow
+++ a/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 -puN drivers/mtd/tests/mtd_pagetest.c~mtd-fix-read-buffer-overflow drivers/mtd/tests/mtd_pagetest.c
--- a/drivers/mtd/tests/mtd_pagetest.c~mtd-fix-read-buffer-overflow
+++ a/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;
 	}
_

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch 7/8] mtd: fix read buffer overflow
  2009-08-06 23:05 [patch 7/8] mtd: fix read buffer overflow akpm
@ 2009-08-10  7:07 ` Artem Bityutskiy
  2009-08-10  7:13 ` Artem Bityutskiy
  1 sibling, 0 replies; 3+ messages in thread
From: Artem Bityutskiy @ 2009-08-10  7:07 UTC (permalink / raw)
  To: akpm; +Cc: roel.kluin, dwmw2, linux-mtd

On Thu, 2009-08-06 at 16:05 -0700, akpm@linux-foundation.org wrote:
> From: Roel Kluin <roel.kluin@gmail.com>
> 
> Check whether index is within bounds before testing the element.
> 
> 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
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> Cc: David Woodhouse <dwmw2@infradead.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

This one is in my l2-mtd-2.6.git as well now.

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch 7/8] mtd: fix read buffer overflow
  2009-08-06 23:05 [patch 7/8] mtd: fix read buffer overflow akpm
  2009-08-10  7:07 ` Artem Bityutskiy
@ 2009-08-10  7:13 ` Artem Bityutskiy
  1 sibling, 0 replies; 3+ messages in thread
From: Artem Bityutskiy @ 2009-08-10  7:13 UTC (permalink / raw)
  To: akpm; +Cc: roel.kluin, dwmw2, linux-mtd

On Thu, 2009-08-06 at 16:05 -0700, akpm@linux-foundation.org wrote:
> From: Roel Kluin <roel.kluin@gmail.com>
> 
> Check whether index is within bounds before testing the element.
> 
> 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
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> Cc: David Woodhouse <dwmw2@infradead.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

This one is in my l2-mtd-2.6.git as well now.

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-10  7:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-06 23:05 [patch 7/8] mtd: fix read buffer overflow akpm
2009-08-10  7:07 ` Artem Bityutskiy
2009-08-10  7:13 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox