03e93e2
From ff9411f6d3f63e765bf29853b920605965a16794 Mon Sep 17 00:00:00 2001
03e93e2
From: Jan Synacek <jan.synacek@gmail.com>
03e93e2
Date: Tue, 3 Jan 2017 21:34:36 +0100
03e93e2
Subject: [PATCH] shared: fix double free in unmask (#5005)
03e93e2
03e93e2
Easily reproducible:
03e93e2
1) systemctl mask foo
03e93e2
2) systemctl unmask foo foo
03e93e2
03e93e2
The problem here is that the *i that is put into todo[] is later freed
03e93e2
in strv_uniq(), which is not directly visible from this patch. Somewhere
03e93e2
further in the code, the string that *i pointed to is freed again. That
03e93e2
happens only when multiple services with the same name/path are specified.
03e93e2
(cherry picked from commit dc7dd61de610e9330abe7014860acfa733887d5e)
03e93e2
---
03e93e2
 src/shared/install.c | 4 ++--
03e93e2
 1 file changed, 2 insertions(+), 2 deletions(-)
03e93e2
03e93e2
diff --git a/src/shared/install.c b/src/shared/install.c
03e93e2
index 96fba6e25b..5f0eec3ccb 100644
03e93e2
--- a/src/shared/install.c
03e93e2
+++ b/src/shared/install.c
03e93e2
@@ -1861,7 +1861,7 @@ int unit_file_unmask(
03e93e2
 
03e93e2
         _cleanup_lookup_paths_free_ LookupPaths paths = {};
03e93e2
         _cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
03e93e2
-        _cleanup_free_ char **todo = NULL;
03e93e2
+        _cleanup_strv_free_ char **todo = NULL;
03e93e2
         size_t n_todo = 0, n_allocated = 0;
03e93e2
         const char *config_path;
03e93e2
         char **i;
03e93e2
@@ -1899,7 +1899,7 @@ int unit_file_unmask(
03e93e2
                 if (!GREEDY_REALLOC0(todo, n_allocated, n_todo + 2))
03e93e2
                         return -ENOMEM;
03e93e2
 
03e93e2
-                todo[n_todo++] = *i;
03e93e2
+                todo[n_todo++] = strdup(*i);
03e93e2
         }
03e93e2
 
03e93e2
         strv_uniq(todo);
03e93e2
-- 
03e93e2
2.9.3
03e93e2