teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0746-fs-util-chase_symlinks-prevent-double-free.patch

923a60
From e4834c7be945dfbb0a6d7f13c736924bf9489cd2 Mon Sep 17 00:00:00 2001
923a60
From: Yu Watanabe <watanabe.yu+github@gmail.com>
923a60
Date: Sun, 21 Jan 2018 19:19:25 +0900
923a60
Subject: [PATCH] fs-util: chase_symlinks(): prevent double free
923a60
923a60
Fixes CID #1385316.
923a60
923a60
(cherry picked from commit b539437a056953cb0b537db4af61f1f1bf97ed44)
923a60
923a60
Resolves: #1714782
923a60
---
923a60
 src/shared/util.c | 4 ++--
923a60
 1 file changed, 2 insertions(+), 2 deletions(-)
923a60
923a60
diff --git a/src/shared/util.c b/src/shared/util.c
923a60
index 354d15ff18..07de902aaf 100644
923a60
--- a/src/shared/util.c
923a60
+++ b/src/shared/util.c
923a60
@@ -9414,8 +9414,6 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
923a60
                                 if (fd < 0)
923a60
                                         return -errno;
923a60
 
923a60
-                                free(done);
923a60
-
923a60
                                 if (flags & CHASE_SAFE) {
923a60
                                         if (fstat(fd, &st) < 0)
923a60
                                                 return -errno;
923a60
@@ -9426,6 +9424,8 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
923a60
                                         previous_stat = st;
923a60
                                 }
923a60
 
923a60
+                                free(done);
923a60
+
923a60
                                 /* Note that we do not revalidate the root, we take it as is. */
923a60
                                 if (isempty(root))
923a60
                                         done = NULL;