anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

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

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