]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pid1: fix segv triggered by status query (#26279)
authorRobin Humble <plaguedbypenguins@gmail.com>
Wed, 1 Feb 2023 12:36:48 +0000 (23:36 +1100)
committerGitHub <noreply@github.com>
Wed, 1 Feb 2023 12:36:48 +0000 (21:36 +0900)
If any query makes it to the end of install_info_follow() then I think symlink_target is set to NULL.
If that is followed by -EXDEV from unit_file_load_or_readlink(), then that causes basename(NULL)
which segfaults pid 1.

This is triggered by eg. "systemctl status crond" in RHEL9 if

/etc/systemd/system/crond.service
  -> /ram/etc/systemd/system/crond.service
  -> /usr/lib/systemd/system/.crond.service.blah.blah
  -> /usr/lib/systemd/system/crond.service

src/shared/install.c

index 51cae3b5a2c11cff3b6e60ed748a22caab7fc605..aa8438e29943fb61b799ca98b307ff3a95c72346 100644 (file)
@@ -1658,7 +1658,7 @@ static int install_info_traverse(
                 r = install_info_follow(ctx, i, lp, flags,
                                         /* If linked, don't look at the target name */
                                         /* ignore_different_name= */ i->install_mode == INSTALL_MODE_LINKED);
-                if (r == -EXDEV) {
+                if (r == -EXDEV && i->symlink_target) {
                         _cleanup_free_ char *buffer = NULL;
                         const char *bn;