Skip to content

Commit

Permalink
mtd: tests: fix read buffer overflows
Browse files Browse the repository at this point in the history
Check whether index is within bounds before testing the element.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
Roel Kluin authored and David Woodhouse committed Sep 4, 2009
1 parent 269c0ee commit c6f7e7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion drivers/mtd/tests/mtd_oobtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
12 changes: 6 additions & 6 deletions drivers/mtd/tests/mtd_pagetest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c6f7e7b

Please sign in to comment.