]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: fix loop device name usage
authorKarel Zak <kzak@redhat.com>
Mon, 5 Aug 2013 14:03:15 +0000 (16:03 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 5 Aug 2013 14:08:34 +0000 (16:08 +0200)
The code is not paranoid enough, loopcxt_set_device() only set the
device name to loopdev struct, but it does not check if the device
really exists.

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/losetup.c

index 217cf9c18a87d6ed8cb9790001b56bc9387c43c0..c1166b03933310dc914c4fa5c78c899c1a8d88be 100644 (file)
@@ -489,7 +489,8 @@ int main(int argc, char **argv)
                        break;
                case 'c':
                        act = A_SET_CAPACITY;
-                       if (loopcxt_set_device(&lc, optarg))
+                       if (!is_loopdev(optarg) ||
+                           loopcxt_set_device(&lc, optarg))
                                err(EXIT_FAILURE, _("%s: failed to use device"),
                                                optarg);
                        break;
@@ -498,7 +499,8 @@ int main(int argc, char **argv)
                        break;
                case 'd':
                        act = A_DELETE;
-                       if (loopcxt_set_device(&lc, optarg))
+                       if (!is_loopdev(optarg) ||
+                           loopcxt_set_device(&lc, optarg))
                                err(EXIT_FAILURE, _("%s: failed to use device"),
                                                optarg);
                        break;
@@ -595,7 +597,8 @@ int main(int argc, char **argv)
                 * losetup [--list] <device>
                 */
                act = A_SHOW_ONE;
-               if (loopcxt_set_device(&lc, argv[optind]))
+               if (!is_loopdev(argv[optind]) ||
+                   loopcxt_set_device(&lc, argv[optind]))
                        err(EXIT_FAILURE, _("%s: failed to use device"),
                                        argv[optind]);
                optind++;
@@ -608,6 +611,7 @@ int main(int argc, char **argv)
 
                if (optind >= argc)
                        errx(EXIT_FAILURE, _("no loop device specified"));
+               /* don't use is_loopdev() here, the device does not have exist yet */
                if (loopcxt_set_device(&lc, argv[optind]))
                        err(EXIT_FAILURE, _("%s: failed to use device"),
                                        argv[optind]);
@@ -685,7 +689,8 @@ int main(int argc, char **argv)
        case A_DELETE:
                res = delete_loop(&lc);
                while (optind < argc) {
-                       if (loopcxt_set_device(&lc, argv[optind]))
+                       if (!is_loopdev(argv[optind]) ||
+                           loopcxt_set_device(&lc, argv[optind]))
                                warn(_("%s: failed to use device"),
                                                argv[optind]);
                        optind++;