From: Yu Watanabe Date: Fri, 28 May 2021 10:48:33 +0000 (+0900) Subject: basic/unit-file: fix use-after-free X-Git-Tag: v249-rc1~130^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7f1238bd04000f3333e8e2fcb82c9c6e18ee3ffc;p=thirdparty%2Fsystemd.git basic/unit-file: fix use-after-free This fixes a bug introduced by e8630e695232bdfcd16b55f3faafb4329c961104. Fixes CID#1453292. --- diff --git a/src/basic/unit-file.c b/src/basic/unit-file.c index fab63b6dcec..f20ae4dbe53 100644 --- a/src/basic/unit-file.c +++ b/src/basic/unit-file.c @@ -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. */