aboutsummaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2011-07-21 21:21:04 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2011-07-21 21:21:04 +0000
commitd8334dbc4b6032a6938f3e741b93ccd48e097d2e (patch)
treea41033f8d22caa096221beaa0942d7c5aec5ed56 /flashrom.c
parentec8c248414d1fe9e163a6003aebb57f003a9123d (diff)
downloadflashrom-d8334dbc4b6032a6938f3e741b93ccd48e097d2e.tar.gz
flashrom-d8334dbc4b6032a6938f3e741b93ccd48e097d2e.tar.bz2
flashrom-d8334dbc4b6032a6938f3e741b93ccd48e097d2e.zip
Fix out-of-bounds access if all erase functions fail
Fix detection of unchanged chip contents on erase failure. Return error if no usable erase functions exist. Thanks to Stefan Tauner for spotting the last problem. Corresponding to flashrom svn r1380. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/flashrom.c b/flashrom.c
index 998a18f5..5ddcd41a 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1507,7 +1507,7 @@ static int check_block_eraser(const struct flashchip *flash, int k, int log)
int erase_and_write_flash(struct flashchip *flash, uint8_t *oldcontents, uint8_t *newcontents)
{
- int k, ret = 0;
+ int k, ret = 1;
uint8_t *curcontents;
unsigned long size = flash->total_size * 1024;
unsigned int usable_erasefunctions = count_usable_erasers(flash);
@@ -1522,8 +1522,12 @@ int erase_and_write_flash(struct flashchip *flash, uint8_t *oldcontents, uint8_t
memcpy(curcontents, oldcontents, size);
for (k = 0; k < NUM_ERASEFUNCTIONS; k++) {
+ if (!usable_erasefunctions) {
+ msg_cdbg("No usable erase functions left.\n");
+ break;
+ }
msg_cdbg("Looking at blockwise erase function %i... ", k);
- if (check_block_eraser(flash, k, 1) && usable_erasefunctions) {
+ if (check_block_eraser(flash, k, 1)) {
msg_cdbg("Looking for another erase function.\n");
continue;
}
@@ -1535,10 +1539,8 @@ int erase_and_write_flash(struct flashchip *flash, uint8_t *oldcontents, uint8_t
if (!ret)
break;
/* Write/erase failed, so try to find out what the current chip
- * contents are. If no usable erase functions remain, we could
- * abort the loop instead of continuing, the effect is the same.
- * The only difference is whether the reason for other unusable
- * functions is printed or not. If in doubt, verbosity wins.
+ * contents are. If no usable erase functions remain, we can
+ * skip this: the next iteration will break immediately anyway.
*/
if (!usable_erasefunctions)
continue;