]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
proc-cmdline: parse the whole /proc/cmdline
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 12 Jun 2023 19:05:30 +0000 (21:05 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 13 Jun 2023 07:54:02 +0000 (09:54 +0200)
The kernel command line may contain newlines which kernel happily
accepts, but we'd ignore everything past the first newline. Let's fix
that by replacing read_one_line_file() with read_full_file().

src/basic/proc-cmdline.c
test/TEST-02-UNITTESTS/test.sh
test/units/testsuite-02.sh

index 39e9f2c668c938a87f3d33efe77865841756cd24..6203b7995972b587e1ba5b65835458ab99fd3859 100644 (file)
@@ -98,7 +98,7 @@ int proc_cmdline(char **ret) {
         if (detect_container() > 0)
                 return get_process_cmdline(1, SIZE_MAX, 0, ret);
         else
-                return read_one_line_file("/proc/cmdline", ret);
+                return read_full_file("/proc/cmdline", ret, NULL);
 }
 
 static int proc_cmdline_strv_internal(char ***ret, bool filter_pid1_args) {
@@ -128,7 +128,7 @@ static int proc_cmdline_strv_internal(char ***ret, bool filter_pid1_args) {
         } else {
                 _cleanup_free_ char *s = NULL;
 
-                r = read_one_line_file("/proc/cmdline", &s);
+                r = read_full_file("/proc/cmdline", &s, NULL);
                 if (r < 0)
                         return r;
 
index 3d766db3e744e4ec094e88b11e9dc9c7eca502b4..3646aa678e45007dbc33caa68f68e453192199ca 100755 (executable)
@@ -14,6 +14,9 @@ KERNEL_APPEND="
 
 frobnicate!
 
+systemd.setenv=TEST_CMDLINE_NEWLINE=foo
+systemd.setenv=TEST_CMDLINE_NEWLINE=bar
+
 $KERNEL_APPEND
 "
 
index d8aaacb913c40c3793598a7ac067b5865843829d..ca54fc4018f99f50b48f9c0562ab82f85b27acb7 100755 (executable)
@@ -3,6 +3,12 @@
 set -eux
 set -o pipefail
 
+if ! systemd-detect-virt -qc && [[ "${TEST_CMDLINE_NEWLINE:-}" != bar ]]; then
+    cat /proc/cmdline
+    echo >&2 "Expected TEST_CMDLINE_NEWLINE=bar from the kernel command line"
+    exit 1
+fi
+
 NPROC=$(nproc)
 MAX_QUEUE_SIZE=${NPROC:-2}
 TESTS_GLOB=${TESTS_GLOB:-test-*}