]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/bootspec: avoid crashing on config without a value
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 6 May 2022 15:36:47 +0000 (17:36 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 8 May 2022 15:58:00 +0000 (17:58 +0200)
src/shared/bootspec.c
test/fuzz/fuzz-bootspec/crash-empty-value [new file with mode: 0644]

index 50875021d42c6c95a8daef344948cdc8385095c9..bc0994f9bd1e45852eb4c73d716bf0c2aa70791d 100644 (file)
@@ -127,6 +127,13 @@ static int boot_entry_load_type1(
                         continue;
                 }
 
+                if (isempty(p)) {
+                        /* Some fields can reasonably have an empty value. In other cases warn. */
+                        if (!STR_IN_SET(field, "options", "devicetree-overlay"))
+                                log_warning("%s:%u: Field %s without value", tmp.path, line, field);
+                        continue;
+                }
+
                 if (streq(field, "title"))
                         r = free_and_strdup(&tmp.title, p);
                 else if (streq(field, "sort-key"))
diff --git a/test/fuzz/fuzz-bootspec/crash-empty-value b/test/fuzz/fuzz-bootspec/crash-empty-value
new file mode 100644 (file)
index 0000000..5436e44
--- /dev/null
@@ -0,0 +1 @@
+{"config": "timeout 3\nconsole-mode 2\n# default 08a5690afeedfeedaaac0a5d2e3cf6b0-*\n# default auto-reboot-to-firmware-set*up\n", "entries": [["08a5690afeedfeedaaac0a5d2e3cf6b0-5.15.14-200.fc35.x86_64.conf", "title      Fedora Linux 35 (Workstation Edition)\nversio'    5.15.14-200.fc35.x86_64\nmachine-id 08a5690afeedfeedaaac0a5d2e3cf6b0\noptions    root=/dev/mapper/fedora_krowka-root rw rd.lvm.lv=fedora_krowka/root rd.luks.uuid=luks-2d9b648a-15b1-4204-988b-ec085085f8ce rd.lvm.lv=fedora_krowka/swap LANG=en_US.UTF-8 selinux=0 resume='dev/mapper/fedora_krowka-swap systemd.show-status systemd.unit-status-format=name quiet\nlinux      /08a5690md.unit-status-format=name quiet\nlinux      /08a5690afeedfeedaaac0a5d2e3cf6b0/5.15.14-200.fc35.x86_64/linux\ninitrd     /08a5690afeedfeedaaac0a5d2e3cf6b0/5.15.14-200.fc35.x86_64/titled\n"], ["08a5690afeedfeedaaac0a5d2e3cf6b0-5.17.47cf92ac0a5d2e3cf6b0-5.17.0-0.rc5.102.fc36.x86_64.conf", "title      Fedora Lin38 6724b7a987ebb5b8495b9ea/3.8.0-2.fc19.armv7hl/tegra20-paz00.dtb\ndevicetree-overlay ", "title      Fedora Lin3x 6724b7a987ebb5b8495_64/initrd\n"], ["08a5690afeedfeedaaac0a5d2e3cf6b0-5.17.0-0.rc5.102.fc36.x86_64.conf", "title      Fedora Lin3x 6724b7a987ebb5b8495b9ea/3.8.0-2.fc19.armv7hl/tegra20-paz00.dtb\ndevicetree-overlay /6a9857a393'24b7a981ebb5b8495b9ea/overlays/overlay_A.dtbo /6a9857a393724b7a981ebb5b8495b9ea/overlays/overlay_B.dtbo\narchitecture IA32\narchitecture x64\narchitecture IA64\narcetithcure ARM\narchitecture AA64\n"]]}