ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
ac3a84
From ba575dced76ed7420c8eaa77942e31b134927524 Mon Sep 17 00:00:00 2001
ac3a84
From: Robin Humble <plaguedbypenguins@gmail.com>
ac3a84
Date: Wed, 1 Feb 2023 23:36:48 +1100
ac3a84
Subject: [PATCH] pid1: fix segv triggered by status query (#26279)
ac3a84
ac3a84
If any query makes it to the end of install_info_follow() then I think symlink_target is set to NULL.
ac3a84
If that is followed by -EXDEV from unit_file_load_or_readlink(), then that causes basename(NULL)
ac3a84
which segfaults pid 1.
ac3a84
ac3a84
This is triggered by eg. "systemctl status crond" in RHEL9 if
ac3a84
ac3a84
/etc/systemd/system/crond.service
ac3a84
  -> /ram/etc/systemd/system/crond.service
ac3a84
  -> /usr/lib/systemd/system/.crond.service.blah.blah
ac3a84
  -> /usr/lib/systemd/system/crond.service
ac3a84
ac3a84
(cherry picked from commit 19cfda9fc3c60de21a362ebb56bcb9f4a9855e85)
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 src/shared/install.c | 2 +-
ac3a84
 1 file changed, 1 insertion(+), 1 deletion(-)
ac3a84
ac3a84
diff --git a/src/shared/install.c b/src/shared/install.c
ac3a84
index 4b610b20a5..a760726628 100644
ac3a84
--- a/src/shared/install.c
ac3a84
+++ b/src/shared/install.c
ac3a84
@@ -1653,7 +1653,7 @@ static int install_info_traverse(
ac3a84
                 r = install_info_follow(ctx, i, lp, flags,
ac3a84
                                         /* If linked, don't look at the target name */
ac3a84
                                         /* ignore_different_name= */ i->install_mode == INSTALL_MODE_LINKED);
ac3a84
-                if (r == -EXDEV) {
ac3a84
+                if (r == -EXDEV && i->symlink_target) {
ac3a84
                         _cleanup_free_ char *buffer = NULL;
ac3a84
                         const char *bn;
ac3a84