aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorRoel Kluin <roel.kluin@gmail.com>2009-07-31 10:21:01 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2009-09-04 04:40:17 -0400
commitc6f7e7beb9e6a64816f534a3a0dd0cfa4937f1fe (patch)
treec0fed3deeb9862dffac83ac45814e70341317c2e /drivers
parent269c0ee66367b11de9758ee64ea039843f0c7cad (diff)
mtd: tests: fix read buffer overflows
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/tests/mtd_oobtest.c2
-rw-r--r--drivers/mtd/tests/mtd_pagetest.c12
2 files changed, 7 insertions, 7 deletions
diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c
index a18e8d2f2557..5553cd4eab20 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)
512 goto out; 512 goto out;
513 513
514 addr0 = 0; 514 addr0 = 0;
515 for (i = 0; bbt[i] && i < ebcnt; ++i) 515 for (i = 0; i < ebcnt && bbt[i]; ++i)
516 addr0 += mtd->erasesize; 516 addr0 += mtd->erasesize;
517 517
518 /* Attempt to write off end of OOB */ 518 /* Attempt to write off end of OOB */
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c
index 9648818b9e2c..103cac480fee 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)
116 loff_t addr = ebnum * mtd->erasesize; 116 loff_t addr = ebnum * mtd->erasesize;
117 117
118 addr0 = 0; 118 addr0 = 0;
119 for (i = 0; bbt[i] && i < ebcnt; ++i) 119 for (i = 0; i < ebcnt && bbt[i]; ++i)
120 addr0 += mtd->erasesize; 120 addr0 += mtd->erasesize;
121 121
122 addrn = mtd->size; 122 addrn = mtd->size;
123 for (i = 0; bbt[ebcnt - i - 1] && i < ebcnt; ++i) 123 for (i = 0; i < ebcnt && bbt[ebcnt - i - 1]; ++i)
124 addrn -= mtd->erasesize; 124 addrn -= mtd->erasesize;
125 125
126 set_random_data(writebuf, mtd->erasesize); 126 set_random_data(writebuf, mtd->erasesize);
@@ -219,11 +219,11 @@ static int crosstest(void)
219 memset(pp1, 0, pgsize * 4); 219 memset(pp1, 0, pgsize * 4);
220 220
221 addr0 = 0; 221 addr0 = 0;
222 for (i = 0; bbt[i] && i < ebcnt; ++i) 222 for (i = 0; i < ebcnt && bbt[i]; ++i)
223 addr0 += mtd->erasesize; 223 addr0 += mtd->erasesize;
224 224
225 addrn = mtd->size; 225 addrn = mtd->size;
226 for (i = 0; bbt[ebcnt - i - 1] && i < ebcnt; ++i) 226 for (i = 0; i < ebcnt && bbt[ebcnt - i - 1]; ++i)
227 addrn -= mtd->erasesize; 227 addrn -= mtd->erasesize;
228 228
229 /* Read 2nd-to-last page to pp1 */ 229 /* Read 2nd-to-last page to pp1 */
@@ -317,7 +317,7 @@ static int erasecrosstest(void)
317 317
318 ebnum = 0; 318 ebnum = 0;
319 addr0 = 0; 319 addr0 = 0;
320 for (i = 0; bbt[i] && i < ebcnt; ++i) { 320 for (i = 0; i < ebcnt && bbt[i]; ++i) {
321 addr0 += mtd->erasesize; 321 addr0 += mtd->erasesize;
322 ebnum += 1; 322 ebnum += 1;
323 } 323 }
@@ -413,7 +413,7 @@ static int erasetest(void)
413 413
414 ebnum = 0; 414 ebnum = 0;
415 addr0 = 0; 415 addr0 = 0;
416 for (i = 0; bbt[i] && i < ebcnt; ++i) { 416 for (i = 0; i < ebcnt && bbt[i]; ++i) {
417 addr0 += mtd->erasesize; 417 addr0 += mtd->erasesize;
418 ebnum += 1; 418 ebnum += 1;
419 } 419 }