From: Glenn Washburn <development@efficientek.com>
To: grub-devel@gnu.org
Cc: Daniel Kiper <dkiper@net-space.pl>,
Glenn Washburn <development@efficientek.com>
Subject: [PATCH v2] loopback: Do not automaticaly replace existing loopback dev, error instead
Date: Thu, 3 Dec 2020 19:57:11 -0600 [thread overview]
Message-ID: <20201204015711.4102520-1-development@efficientek.com> (raw)
In-Reply-To: <20201127083624.3482953-1-development@efficientek.com>
If there is a loopback device with the same name as the one to be created,
instead of closing the old one and replacing it with the new one, return an
error instead. If the loopback device was created, its probably being used
by something and just replacing it may cause grub to crash unexpectedly.
This fixes obvious problems like `loopback d (d)/somefile'. Its not too
onerous to force the user to delete the loopback first with the `-d' switch.
Signed-off-by: Glenn Washburn <development@efficientek.com>
---
grub-core/disk/loopback.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/grub-core/disk/loopback.c b/grub-core/disk/loopback.c
index cdf9123fa..ef3a05fec 100644
--- a/grub-core/disk/loopback.c
+++ b/grub-core/disk/loopback.c
@@ -92,24 +92,16 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
if (argc < 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
+ /* Check that a device with requested name does not already exist. */
+ for (newdev = loopback_list; newdev; newdev = newdev->next)
+ if (grub_strcmp (newdev->devname, args[0]) == 0)
+ return grub_error(GRUB_ERR_BAD_ARGUMENT, "device name already exists");
+
file = grub_file_open (args[1], GRUB_FILE_TYPE_LOOPBACK
| GRUB_FILE_TYPE_NO_DECOMPRESS);
if (! file)
return grub_errno;
- /* First try to replace the old device. */
- for (newdev = loopback_list; newdev; newdev = newdev->next)
- if (grub_strcmp (newdev->devname, args[0]) == 0)
- break;
-
- if (newdev)
- {
- grub_file_close (newdev->file);
- newdev->file = file;
-
- return 0;
- }
-
/* Unable to replace it, make a new entry. */
newdev = grub_malloc (sizeof (struct grub_loopback));
if (! newdev)
--
2.27.0
next prev parent reply other threads:[~2020-12-04 1:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-27 8:36 [PATCH] disk: Move hardcoded max disk size literal to a GRUB_DISK_MAX_SECTORS in disk.h Glenn Washburn
2020-11-27 8:36 ` [PATCH] loopback: Do not automaticaly replace existing loopback dev, error instead Glenn Washburn
2020-12-02 14:36 ` Daniel Kiper
2020-12-04 11:45 ` Glenn Washburn
2020-11-30 14:42 ` [PATCH] disk: Move hardcoded max disk size literal to a GRUB_DISK_MAX_SECTORS in disk.h Daniel Kiper
2020-12-01 5:15 ` Glenn Washburn
2020-12-01 5:16 ` [PATCH v2] " Glenn Washburn
2020-12-02 14:28 ` Daniel Kiper
2020-12-04 1:57 ` Glenn Washburn [this message]
2020-12-04 12:34 ` [PATCH v2] loopback: Do not automaticaly replace existing loopback dev, error instead Daniel Kiper
2020-12-08 4:52 ` Glenn Washburn
2020-12-10 16:55 ` Daniel Kiper
2020-12-11 22:36 ` Glenn Washburn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201204015711.4102520-1-development@efficientek.com \
--to=development@efficientek.com \
--cc=dkiper@net-space.pl \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.