dcavalca / rpms / systemd

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