fs-util: chase_symlinks(): prevent double free
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 21 Jan 2018 10:19:25 +0000 (19:19 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 21 Jan 2018 10:19:28 +0000 (19:19 +0900)
Fixes CID #1385316.

src/basic/fs-util.c

index 87d743b..a8e50d4 100644 (file)
@@ -834,8 +834,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;
@@ -846,6 +844,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;