From 451f0dba60b04c6a20a82e683ba117efa609b814 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 21 Dec 2022 16:48:25 +0100 Subject: [PATCH] =?utf8?q?mount-tool:=20port=20over=20basename()=20?= =?utf8?q?=E2=86=92=20path=5Fextract=5Ffilename()?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/mount/mount-tool.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index f7dd705c5e6..ea6d528189a 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -1104,12 +1104,13 @@ static const char* get_label(sd_device *d) { static int acquire_mount_where(sd_device *d) { const char *v; + int r; if (arg_mount_where) return 0; if (sd_device_get_property_value(d, "SYSTEMD_MOUNT_WHERE", &v) < 0) { - _cleanup_free_ char *escaped = NULL; + _cleanup_free_ char *escaped = NULL, *devname_bn = NULL; const char *name; name = get_label(d); @@ -1121,7 +1122,11 @@ static int acquire_mount_where(sd_device *d) { if (sd_device_get_devname(d, &dn) < 0) return 0; - name = basename(dn); + r = path_extract_filename(dn, &devname_bn); + if (r < 0) + return log_error_errno(r, "Failed to extract file name from '%s': %m", dn); + + name = devname_bn; } escaped = xescape(name, "\\"); @@ -1253,12 +1258,16 @@ static int discover_loop_backing_file(void) { return log_error_errno(errno, "Can't get loop device for %s: %m", arg_mount_what); if (r == -ENXIO) { - _cleanup_free_ char *escaped = NULL; + _cleanup_free_ char *escaped = NULL, *bn = NULL; if (arg_mount_where) return 0; - escaped = xescape(basename(arg_mount_what), "\\"); + r = path_extract_filename(arg_mount_what, &bn); + if (r < 0) + return log_error_errno(r, "Failed to extract file name from backing file path '%s': %m", arg_mount_what); + + escaped = xescape(bn, "\\"); if (!escaped) return log_oom(); if (!filename_is_valid(escaped)) -- 2.47.3