From 21ce3f3a4ec1a7cf97379aa4157cecc657cb814e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 5 Aug 2013 16:03:15 +0200 Subject: 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 --- sys-utils/losetup.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'sys-utils/losetup.c') 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] */ 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++; -- cgit v1.2.3-55-g7522