summaryrefslogtreecommitdiff
path: root/misc/tune2fs.c
diff options
context:
space:
mode:
authorLukas Czerner <lczerner@redhat.com>2022-08-12 15:01:22 +0200
committerTheodore Ts'o <tytso@mit.edu>2022-08-12 22:32:14 -0400
commit18ebcf26f478702cd09dd4229320d449469f1490 (patch)
treee26859b9e05fee3451224f5d5a28efcb62a55138 /misc/tune2fs.c
parent64d576a89959bfdcf5415be2c36c06549562cbb2 (diff)
downloade2fsprogs-18ebcf26f478702cd09dd4229320d449469f1490.tar.gz
e2fsprogs: fix device name parsing to resolve names containing '='
Currently in varisous e2fsprogs tools, most notably tune2fs and e2fsck we will get the device name by passing the user provided string into blkid_get_devname(). This library function however is primarily intended for parsing "NAME=value" tokens. It will return the device matching the specified token, NULL if nothing is found, or copy of the string if it's not in "NAME=value" format. However in case where we're passing in a file name that contains an equal sign blkid_get_devname() will treat it as a token and will attempt to find the device with the match. Likely finding nothing. Fix it by checking existence of the file first and then attempt to call blkid_get_devname(). In case of a collision, notify the user and automatically prefer the one returned by blkid_get_devname(). Otherwise return either the existing file, or NULL. We do it this way to avoid some existing file in working directory (for example LABEL=volume-name) masking an actual device containing the matchin LABEL. User can specify full, or relative path (e.g. ./LABEL=volume-name) to make sure the file is used instead. Link: https://lore.kernel.org/r/20220812130122.69468-1-lczerner@redhat.com Signed-off-by: Lukas Czerner <lczerner@redhat.com> Reported-by: Daniel Ng <danielng@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'misc/tune2fs.c')
-rw-r--r--misc/tune2fs.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 64a456af..a7ff16de 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -59,6 +59,7 @@ extern int optind;
#include "et/com_err.h"
#include "support/plausible.h"
#include "support/quotaio.h"
+#include "support/devname.h"
#include "uuid/uuid.h"
#include "e2p/e2p.h"
#include "util.h"
@@ -1774,7 +1775,7 @@ static void parse_e2label_options(int argc, char ** argv)
io_options = strchr(argv[1], '?');
if (io_options)
*io_options++ = 0;
- device_name = blkid_get_devname(NULL, argv[1], NULL);
+ device_name = get_devname(NULL, argv[1], NULL);
if (!device_name) {
com_err("e2label", 0, _("Unable to resolve '%s'"),
argv[1]);
@@ -2074,7 +2075,7 @@ static void parse_tune2fs_options(int argc, char **argv)
io_options = strchr(argv[optind], '?');
if (io_options)
*io_options++ = 0;
- device_name = blkid_get_devname(NULL, argv[optind], NULL);
+ device_name = get_devname(NULL, argv[optind], NULL);
if (!device_name) {
com_err(program_name, 0, _("Unable to resolve '%s'"),
argv[optind]);