1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-21 18:03:41 +03:00

basic/unit-file: fix use-after-free

This fixes a bug introduced by e8630e695232bdfcd16b55f3faafb4329c961104.

Fixes CID#1453292.

(cherry picked from commit 7f1238bd04000f3333e8e2fcb82c9c6e18ee3ffc)
(cherry picked from commit 218117da2a8b4f1eccfc61353fdbe01219696378)
(cherry picked from commit 5c86f9e0381dadc06650492cd68b28ed800d376d)
This commit is contained in:
Yu Watanabe 2021-05-28 19:48:33 +09:00 committed by Zbigniew Jędrzejewski-Szmek
parent 9702878676
commit d986423249

View 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. */