]> www.infradead.org Git - mtd-utils.git/commitdiff
ubi-utils: improve input parameters checks
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 23 Apr 2008 15:05:05 +0000 (18:05 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 23 Apr 2008 15:05:05 +0000 (18:05 +0300)
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
ubi-utils/new-utils/src/ubiformat.c
ubi-utils/new-utils/src/ubinize.c

index fe08f6f21583323f38ec8b86da8c8af46d064b62..8d13237fa8e695e5da2cb7dacb1bb5784ac8b6f4 100644 (file)
@@ -135,7 +135,7 @@ static int parse_opt(int argc, char * const argv[])
 
                case 'O':
                        args.vid_hdr_offs = strtoul(optarg, &endp, 0);
-                       if (args.vid_hdr_offs < 0 || *endp != '\0' || endp == optarg)
+                       if (args.vid_hdr_offs <= 0 || *endp != '\0' || endp == optarg)
                                return errmsg("bad VID header offset: \"%s\"", optarg);
                        break;
 
@@ -523,12 +523,25 @@ int main(int argc, char * const argv[])
                args.subpage_size = mtd.min_io_size;
        else {
                if (args.subpage_size > mtd.min_io_size) {
-                       errmsg("sub-page cannot be larger then min. I/O unit");
+                       errmsg("sub-page cannot be larger than min. I/O unit");
                        goto out_close;
                }
 
                if (mtd.min_io_size % args.subpage_size) {
                        errmsg("min. I/O unit size should be multiple of sub-page size");
+                       goto out_close;
+               }
+       }
+
+       /* Validate VID header offset if it was specified */
+       if (args.vid_hdr_offs != 0) {
+               if (args.vid_hdr_offs % 8) {
+                       errmsg("VID header offset has to be multiple of min. I/O unit size");
+                       goto out_close;
+               }
+               if (args.vid_hdr_offs + UBI_VID_HDR_SIZE > mtd.eb_size) {
+                       errmsg("bad VID header offset");
+                       goto out_close;
                }
        }
 
index 704d90683d1fde40ed30c973ff81e796d08591e6..8ba8869a824c2b825397cab3babed9a00bc04d86 100644 (file)
@@ -239,6 +239,9 @@ static int parse_opt(int argc, char * const argv[])
        if (args.peb_size < 0)
                return errmsg("physical eraseblock size was not specified (use -h for help)");
 
+       if (args.peb_size > 1024*1024)
+               return errmsg("too high physical eraseblock size %d", args.peb_size);
+
        if (args.min_io_size < 0)
                return errmsg("min. I/O unit size was not specified (use -h for help)");
 
@@ -257,8 +260,12 @@ static int parse_opt(int argc, char * const argv[])
        if (!args.f_out)
                return errmsg("output file was not specified (use -h for help)");
 
-       if (args.vid_hdr_offs && args.vid_hdr_offs + UBI_VID_HDR_SIZE >= args.peb_size)
-               return errmsg("bad VID header position");
+       if (args.vid_hdr_offs) {
+               if (args.vid_hdr_offs + UBI_VID_HDR_SIZE >= args.peb_size)
+                       return errmsg("bad VID header position");
+               if (args.vid_hdr_offs % 8)
+                       return errmsg("VID header offset has to be multiple of min. I/O unit size");
+       }
 
        return 0;
 }