Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-updates-src > by-pkgid > a2af656ce25b3c61f78ec27a806d81f0 > files > 92

systemd-241-8.2.mga7.src.rpm

From 3d835d09f29151c97af7cb1116e192df711587ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Fri, 5 Apr 2019 10:17:03 +0200
Subject: [PATCH 191/264] pid1,shutdown: do not cunescape paths from libmount

The test added in previous commit shows that libmount does the unescaping
internally.

(cherry picked from commit 9d1b2b225242fd3514d251c517e37fd97025131b)
---
 src/core/mount.c  | 12 ++----------
 src/core/umount.c | 40 ++++++++++++++++++----------------------
 2 files changed, 20 insertions(+), 32 deletions(-)

diff --git a/src/core/mount.c b/src/core/mount.c
index 9ba1e98554..6652900d7b 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -11,7 +11,6 @@
 #include "dbus-mount.h"
 #include "dbus-unit.h"
 #include "device.h"
-#include "escape.h"
 #include "exit-status.h"
 #include "format-util.h"
 #include "fstab-util.h"
@@ -1635,7 +1634,6 @@ static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) {
         for (;;) {
                 struct libmnt_fs *fs;
                 const char *device, *path, *options, *fstype;
-                _cleanup_free_ char *d = NULL, *p = NULL;
                 int k;
 
                 k = mnt_table_next_fs(t, i, &fs);
@@ -1652,15 +1650,9 @@ static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) {
                 if (!device || !path)
                         continue;
 
-                if (cunescape(device, UNESCAPE_RELAX, &d) < 0)
-                        return log_oom();
+                device_found_node(m, device, DEVICE_FOUND_MOUNT, DEVICE_FOUND_MOUNT);
 
-                if (cunescape(path, UNESCAPE_RELAX, &p) < 0)
-                        return log_oom();
-
-                device_found_node(m, d, DEVICE_FOUND_MOUNT, DEVICE_FOUND_MOUNT);
-
-                (void) mount_setup_unit(m, d, p, options, fstype, set_flags);
+                (void) mount_setup_unit(m, device, path, options, fstype, set_flags);
         }
 
         return 0;
diff --git a/src/core/umount.c b/src/core/umount.c
index 9c0393fa93..794faf76b2 100644
--- a/src/core/umount.c
+++ b/src/core/umount.c
@@ -71,11 +71,10 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
                 struct libmnt_fs *fs;
                 const char *path, *fstype;
                 _cleanup_free_ char *options = NULL;
-                _cleanup_free_ char *p = NULL;
                 unsigned long remount_flags = 0u;
                 _cleanup_free_ char *remount_options = NULL;
                 bool try_remount_ro;
-                MountPoint *m;
+                _cleanup_free_ MountPoint *m = NULL;
 
                 r = mnt_table_next_fs(t, i, &fs);
                 if (r == 1)
@@ -87,18 +86,15 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
                 if (!path)
                         continue;
 
-                if (cunescape(path, UNESCAPE_RELAX, &p) < 0)
-                        return log_oom();
-
                 fstype = mnt_fs_get_fstype(fs);
 
                 /* Combine the generic VFS options with the FS-specific
                  * options. Duplicates are not a problem here, because the only
                  * options that should come up twice are typically ro/rw, which
-                 * are turned into MS_RDONLY or the invertion of it.
+                 * are turned into MS_RDONLY or the inversion of it.
                  *
                  * Even if there are duplicates later in mount_option_mangle()
-                 * it shouldn't hurt anyways as they override each other.
+                 * they shouldn't hurt anyways as they override each other.
                  */
                 if (!strextend_with_separator(&options, ",",
                                               mnt_fs_get_vfs_options(fs),
@@ -116,9 +112,9 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
                  * and hence not worth spending time on. Also, in
                  * unprivileged containers we might lack the rights to
                  * unmount these things, hence don't bother. */
-                if (mount_point_is_api(p) ||
-                    mount_point_ignore(p) ||
-                    PATH_STARTSWITH_SET(p, "/dev", "/sys", "/proc"))
+                if (mount_point_is_api(path) ||
+                    mount_point_ignore(path) ||
+                    PATH_STARTSWITH_SET(path, "/dev", "/sys", "/proc"))
                         continue;
 
                 /* If we are in a container, don't attempt to
@@ -164,12 +160,15 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) {
                 if (!m)
                         return log_oom();
 
-                free_and_replace(m->path, p);
-                free_and_replace(m->remount_options, remount_options);
+                m->path = strdup(path);
+                if (!m->path)
+                        return log_oom();
+
+                m->remount_options = TAKE_PTR(remount_options);
                 m->remount_flags = remount_flags;
                 m->try_remount_ro = try_remount_ro;
 
-                LIST_PREPEND(mount_point, *head, m);
+                LIST_PREPEND(mount_point, *head, TAKE_PTR(m));
         }
 
         return 0;
@@ -193,10 +192,8 @@ int swap_list_get(const char *swaps, MountPoint **head) {
 
         for (;;) {
                 struct libmnt_fs *fs;
-
-                MountPoint *swap;
+                _cleanup_free_ MountPoint *swap = NULL;
                 const char *source;
-                _cleanup_free_ char *d = NULL;
 
                 r = mnt_table_next_fs(t, i, &fs);
                 if (r == 1)
@@ -208,16 +205,15 @@ int swap_list_get(const char *swaps, MountPoint **head) {
                 if (!source)
                         continue;
 
-                r = cunescape(source, UNESCAPE_RELAX, &d);
-                if (r < 0)
-                        return r;
-
                 swap = new0(MountPoint, 1);
                 if (!swap)
                         return -ENOMEM;
 
-                free_and_replace(swap->path, d);
-                LIST_PREPEND(mount_point, *head, swap);
+                swap->path = strdup(source);
+                if (!swap->path)
+                        return -ENOMEM;
+
+                LIST_PREPEND(mount_point, *head, TAKE_PTR(swap));
         }
 
         return 0;
-- 
2.22.1