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