mtd: mtdconcat: prevent a read from eraseregions[-1]
authorRoel Kluin <roel.kluin@gmail.com>
Fri, 18 Sep 2009 19:51:49 +0000 (12:51 -0700)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Sat, 19 Sep 2009 18:18:46 +0000 (11:18 -0700)
If the erase region was found in the first iteration we read from
eraseregions[-1]

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/mtdconcat.c

index 792b547786b8fdf6c4122f28240b1458c0d80f66..db6de74082ad647d0540b0904e35dacec9c707c9 100644 (file)
@@ -427,7 +427,7 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
                 * to-be-erased area begins. Verify that the starting
                 * offset is aligned to this region's erase size:
                 */
-               if (instr->addr & (erase_regions[i].erasesize - 1))
+               if (i < 0 || instr->addr & (erase_regions[i].erasesize - 1))
                        return -EINVAL;
 
                /*
@@ -440,8 +440,8 @@ static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
                /*
                 * check if the ending offset is aligned to this region's erase size
                 */
-               if ((instr->addr + instr->len) & (erase_regions[i].erasesize -
-                                                 1))
+               if (i < 0 || ((instr->addr + instr->len) &
+                                       (erase_regions[i].erasesize - 1)))
                        return -EINVAL;
        }