[PATCH] ubiformat: check file size

Jan Weitzel j.weitzel at phytec.de
Mon Jun 24 03:30:45 EDT 2013


If size of a flash image file is 0 ubiformat silently formats the volume.
Check size and abort if size == 0. This may be the case if an empty or tftp
mounted file is used.

Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
---
 commands/ubiformat.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/commands/ubiformat.c b/commands/ubiformat.c
index 121816f..5b4e572 100644
--- a/commands/ubiformat.c
+++ b/commands/ubiformat.c
@@ -325,6 +325,11 @@ static int flash_image(const struct mtd_dev_info *mtd,
 		goto out_close;
 	}
 
+	if (st_size == 0) {
+		sys_errmsg("file \"%s\" has size 0 bytes", args.image);
+		goto out_close;
+	}
+
 	verbose(args.verbose, "will write %d eraseblocks", img_ebs);
 	divisor = img_ebs;
 	for (eb = 0; eb < mtd->eb_cnt; eb++) {
-- 
1.7.0.4




More information about the barebox mailing list