mirror of
https://github.com/CTCaer/CTCaer-CWM.git
synced 2024-11-26 19:40:54 +00:00
mtdutils: fix crash on large erase block
allocate heap instead of stack for verify[]. otherwise it crashes on large erase block size e.g. 8MiB. Change-Id: Ifaeb1e381af2b4bbdbeb7337848818299d7f441b
This commit is contained in:
parent
c9d07dc238
commit
35ced47771
@ -406,6 +406,11 @@ static int write_block(MtdWriteContext *ctx, const char *data)
|
||||
if (pos == (off_t) -1) return 1;
|
||||
|
||||
ssize_t size = partition->erase_size;
|
||||
|
||||
char *verify = malloc(size);
|
||||
if (verify == NULL)
|
||||
return 1;
|
||||
|
||||
while (pos + size <= (int) partition->size) {
|
||||
loff_t bpos = pos;
|
||||
int ret = ioctl(fd, MEMGETBADBLOCK, &bpos);
|
||||
@ -434,7 +439,6 @@ static int write_block(MtdWriteContext *ctx, const char *data)
|
||||
pos, strerror(errno));
|
||||
}
|
||||
|
||||
char verify[size];
|
||||
if (lseek(fd, pos, SEEK_SET) != pos ||
|
||||
read(fd, verify, size) != size) {
|
||||
fprintf(stderr, "mtd: re-read error at 0x%08lx (%s)\n",
|
||||
@ -451,6 +455,7 @@ static int write_block(MtdWriteContext *ctx, const char *data)
|
||||
fprintf(stderr, "mtd: wrote block after %d retries\n", retry);
|
||||
}
|
||||
fprintf(stderr, "mtd: successfully wrote block at %llx\n", pos);
|
||||
free(verify);
|
||||
return 0; // Success!
|
||||
}
|
||||
|
||||
@ -461,6 +466,8 @@ static int write_block(MtdWriteContext *ctx, const char *data)
|
||||
pos += partition->erase_size;
|
||||
}
|
||||
|
||||
free(verify);
|
||||
|
||||
// Ran out of space on the device
|
||||
errno = ENOSPC;
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user