ryantimwilson / rpms / systemd

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