Whamcloud - gitweb
e2fsprogs: fix device name parsing to resolve names containing '='
authorLukas Czerner <lczerner@redhat.com>
Fri, 12 Aug 2022 13:01:22 +0000 (15:01 +0200)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 13 Aug 2022 02:32:14 +0000 (22:32 -0400)
commit18ebcf26f478702cd09dd4229320d449469f1490
treee26859b9e05fee3451224f5d5a28efcb62a55138
parent64d576a89959bfdcf5415be2c36c06549562cbb2
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>
e2fsck/Makefile.in
e2fsck/unix.c
lib/support/Makefile.in
lib/support/devname.c [new file with mode: 0644]
lib/support/devname.h [new file with mode: 0644]
misc/Makefile.in
misc/e2initrd_helper.c
misc/fsck.c
misc/tune2fs.c
misc/util.c