]> www.infradead.org Git - mtd-utils.git/commitdiff
mtd-utils: fix input parameter checks
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 23 Apr 2008 10:48:09 +0000 (13:48 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 23 Apr 2008 10:48:09 +0000 (13:48 +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 dfae41551414e90f25d40467ad074dc1af11c098..fe08f6f21583323f38ec8b86da8c8af46d064b62 100644 (file)
@@ -135,13 +135,13 @@ static int parse_opt(int argc, char * const argv[])
 
                case 'O':
                        args.vid_hdr_offs = strtoul(optarg, &endp, 0);
-                       if (endp == optarg || args.vid_hdr_offs < 0)
+                       if (args.vid_hdr_offs < 0 || *endp != '\0' || endp == optarg)
                                return errmsg("bad VID header offset: \"%s\"", optarg);
                        break;
 
                case 'e':
                        args.ec = strtoull(optarg, &endp, 0);
-                       if (endp == optarg || args.ec <= 0 || *endp != '\0')
+                       if (args.ec <= 0 || *endp != '\0' || endp == optarg)
                                return errmsg("bad erase counter value: \"%s\"", optarg);
                        if (args.ec >= EC_MAX)
                                return errmsg("too high erase %llu, counter, max is %u", args.ec, EC_MAX);
@@ -166,7 +166,7 @@ static int parse_opt(int argc, char * const argv[])
 
                case 'x':
                        args.ubi_ver = strtoul(optarg, &endp, 0);
-                       if (endp == optarg || args.ubi_ver < 0)
+                       if (args.ubi_ver < 0 || *endp != '\0' || endp == optarg)
                                return errmsg("bad UBI version: \"%s\"", optarg);
                        break;
 
index cd4952d4e1f559bfaabf0b5e8b7366dde1bd4f9d..704d90683d1fde40ed30c973ff81e796d08591e6 100644 (file)
@@ -191,19 +191,19 @@ static int parse_opt(int argc, char * const argv[])
 
                case 'O':
                        args.vid_hdr_offs = strtoul(optarg, &endp, 0);
-                       if (endp == optarg || args.vid_hdr_offs < 0)
+                       if (*endp != '\0' || endp == optarg || args.vid_hdr_offs < 0)
                                return errmsg("bad VID header offset: \"%s\"", optarg);
                        break;
 
                case 'e':
                        args.ec = strtoul(optarg, &endp, 0);
-                       if (endp == optarg || args.ec < 0)
+                       if (*endp != '\0' || endp == optarg || args.ec < 0)
                                return errmsg("bad erase counter value: \"%s\"", optarg);
                        break;
 
                case 'x':
                        args.ubi_ver = strtoul(optarg, &endp, 0);
-                       if (endp == optarg || args.ubi_ver < 0)
+                       if (*endp != '\0'  || endp == optarg || args.ubi_ver < 0)
                                return errmsg("bad UBI version: \"%s\"", optarg);
                        break;