summaryrefslogtreecommitdiffstats
path: root/sys-utils/losetup.c
diff options
context:
space:
mode:
authorKarel Zak2013-08-05 16:03:15 +0200
committerKarel Zak2013-08-05 16:08:34 +0200
commit21ce3f3a4ec1a7cf97379aa4157cecc657cb814e (patch)
tree932a42350976bf7403d558a531a274877522b8f5 /sys-utils/losetup.c
parentlibmount: be robust when work with loopdev backing file paths (diff)
downloadkernel-qcow2-util-linux-21ce3f3a4ec1a7cf97379aa4157cecc657cb814e.tar.gz
kernel-qcow2-util-linux-21ce3f3a4ec1a7cf97379aa4157cecc657cb814e.tar.xz
kernel-qcow2-util-linux-21ce3f3a4ec1a7cf97379aa4157cecc657cb814e.zip
losetup: fix loop device name usage
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>
Diffstat (limited to 'sys-utils/losetup.c')
-rw-r--r--sys-utils/losetup.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index 217cf9c18..c1166b039 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -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++;