]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot-entry: use chase_and_fopen_unlocked() to open /etc/kernel/entry-token
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 12 Apr 2023 07:15:03 +0000 (16:15 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 12 Apr 2023 07:23:03 +0000 (16:23 +0900)
Otherwise, when 'root' is specified, the file may be a symlink to a host
file, and we may read wrong entry.

src/shared/boot-entry.c

index 23877fecba7c9be14f21b35a07bf5276180eb50b..62d3de64ad87f3cad5aef343fa1b15d053b6a50c 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include "boot-entry.h"
+#include "chase.h"
+#include "fd-util.h"
 #include "fileio.h"
 #include "id128-util.h"
 #include "os-util.h"
@@ -14,6 +16,7 @@ bool boot_entry_token_valid(const char *p) {
 
 static int entry_token_load(const char *root, const char *etc_kernel, BootEntryTokenType *type, char **token) {
         _cleanup_free_ char *buf = NULL, *p = NULL;
+        _cleanup_fclose_ FILE *f = NULL;
         int r;
 
         assert(type);
@@ -23,13 +26,17 @@ static int entry_token_load(const char *root, const char *etc_kernel, BootEntryT
         if (!etc_kernel)
                 return 0;
 
-        p = path_join(root, etc_kernel, "entry-token");
+        p = path_join(etc_kernel, "entry-token");
         if (!p)
                 return log_oom();
 
-        r = read_one_line_file(p, &buf);
+        r = chase_and_fopen_unlocked(p, root, CHASE_PREFIX_ROOT, "re", NULL, &f);
         if (r == -ENOENT)
                 return 0;
+        if (r < 0)
+                return log_error_errno(r, "Failed to chase and open '%s': %m", p);
+
+        r = read_line(f, NAME_MAX, &buf);
         if (r < 0)
                 return log_error_errno(r, "Failed to read %s: %m", p);