dcavalca / rpms / systemd

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