]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/unit: fix superficial NULL-pointer dereference 31367/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 17 Feb 2024 07:50:42 +0000 (16:50 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 17 Feb 2024 07:50:46 +0000 (16:50 +0900)
Though, when unit_prepare_exec() is called, the unit should always
have the cgroup runtime context 'crt'. So, I think we can insert assert().
But, for consistency with other places that call unit_get_cgroup_runtime(),
here use the simple non-NULL check for 'crt' instead of using assert().

Follow-up for 9cc545447e31ed38d71c00d5957c4dee0b5bce97.

Fixes CID#1534667.

src/core/unit.c

index df99fff9d271d0c9cd9c09faa71e1f38cf626a9e..2c6a0b3e5727c0e5c3302881c113a9248e6d20ed 100644 (file)
@@ -5813,7 +5813,7 @@ int unit_prepare_exec(Unit *u) {
         (void) unit_realize_cgroup(u);
 
         CGroupRuntime *crt = unit_get_cgroup_runtime(u);
-        if (crt->reset_accounting) {
+        if (crt && crt->reset_accounting) {
                 (void) unit_reset_accounting(u);
                 crt->reset_accounting = false;
         }