Skip to content

Commit 4382d47

Browse files
shenkistewartsmith
authored andcommitted
pflash: Fail when file is larger than partition
Currently we warn the user and truncate the file by default. Instead abort as this is rarely the desired behaviour. You can still shoot yourself in the foot by passing --force. Signed-off-by: Joel Stanley <[email protected]> Reviewed-by: Cyril Bur <[email protected]> Signed-off-by: Stewart Smith <[email protected]>
1 parent 30f86e5 commit 4382d47

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: external/pflash/pflash.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -839,14 +839,20 @@ int main(int argc, char *argv[])
839839
if (!write_size)
840840
write_size = pmaxsz;
841841

842-
/* Crop write size to partition size */
843-
if (write_size > pmaxsz) {
842+
/* Crop write size to partition size if --force was passed */
843+
if (write_size > pmaxsz && !must_confirm) {
844844
printf("WARNING: Size (%d bytes) larger than partition"
845845
" (%d bytes), cropping to fit\n",
846846
write_size, pmaxsz);
847847
write_size = pmaxsz;
848+
} else if (write_size > pmaxsz) {
849+
printf("ERROR: Size (%d bytes) larger than partition"
850+
" (%d bytes). Use --force to force\n",
851+
write_size, pmaxsz);
852+
exit(1);
848853
}
849854

855+
850856
/* If erasing, check partition alignment */
851857
if (erase && ((pstart | pmaxsz) & 0xfff)) {
852858
fprintf(stderr,"Partition not aligned properly\n");

0 commit comments

Comments
 (0)