]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/unit-file: fix use-after-free
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 28 May 2021 10:48:33 +0000 (19:48 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 28 May 2021 10:48:38 +0000 (19:48 +0900)
This fixes a bug introduced by e8630e695232bdfcd16b55f3faafb4329c961104.

Fixes CID#1453292.

src/basic/unit-file.c

index fab63b6dcece9f1d55b0ffda1f9862c56b82f3e4..f20ae4dbe5343b69b3d4223a3ac597abb3a43ad1 100644 (file)
@@ -303,11 +303,11 @@ int unit_file_build_name_map(
                                 return log_oom();
 
                         if (paths) {
-                                r = set_consume(paths, filename);
+                                r = set_put(paths, filename);
                                 if (r < 0)
                                         return log_oom();
-                                /* We will still use filename below. This is safe because we know the set
-                                 * holds a reference. */
+                                if (r == 0)
+                                        _filename_free = filename; /* Make sure we free the filename. */
                         } else
                                 _filename_free = filename; /* Make sure we free the filename. */