valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone
Blob Blame History Raw
From e4834c7be945dfbb0a6d7f13c736924bf9489cd2 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Sun, 21 Jan 2018 19:19:25 +0900
Subject: [PATCH] fs-util: chase_symlinks(): prevent double free

Fixes CID #1385316.

(cherry picked from commit b539437a056953cb0b537db4af61f1f1bf97ed44)

Resolves: #1714782
---
 src/shared/util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/shared/util.c b/src/shared/util.c
index 354d15ff18..07de902aaf 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -9414,8 +9414,6 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
                                 if (fd < 0)
                                         return -errno;
 
-                                free(done);
-
                                 if (flags & CHASE_SAFE) {
                                         if (fstat(fd, &st) < 0)
                                                 return -errno;
@@ -9426,6 +9424,8 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
                                         previous_stat = st;
                                 }
 
+                                free(done);
+
                                 /* Note that we do not revalidate the root, we take it as is. */
                                 if (isempty(root))
                                         done = NULL;