yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-fw_cfg-Fix-boot-bootsplash-error-checking.patch

016a62
From f798645d16957453ee49a5a2945ed80eeb87cd15 Mon Sep 17 00:00:00 2001
016a62
From: Markus Armbruster <armbru@redhat.com>
016a62
Date: Mon, 7 Oct 2019 07:35:07 +0100
016a62
Subject: [PATCH 14/22] fw_cfg: Fix -boot bootsplash error checking
016a62
MIME-Version: 1.0
016a62
Content-Type: text/plain; charset=UTF-8
016a62
Content-Transfer-Encoding: 8bit
016a62
016a62
RH-Author: Markus Armbruster <armbru@redhat.com>
016a62
Message-id: <20191007073509.5887-3-armbru@redhat.com>
016a62
Patchwork-id: 90980
016a62
O-Subject: [RHEL-8.2.0 qemu-kvm PATCH v2 2/4] fw_cfg: Fix -boot bootsplash error checking
016a62
Bugzilla: 1607367
016a62
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
016a62
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
016a62
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
016a62
016a62
From: Li Qiang <liq3ea@gmail.com>
016a62
016a62
fw_cfg_bootsplash() gets option parameter "splash-time"
016a62
with qemu_opt_get(), then converts it to an integer by hand.
016a62
It neglects to check that conversion for errors. This is
016a62
needlessly complicated and error-prone. But as "splash-time
016a62
not specified" is not the same as "splash-time=T" for any T,
016a62
we need use qemu_opt_get() to check if splash time exists.
016a62
This patch also make the qemu exit when finding or loading
016a62
splash file failed.
016a62
016a62
Signed-off-by: Li Qiang <liq3ea@gmail.com>
016a62
Reviewed-by: Markus Armbruster <armbru@redhat.com>
016a62
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
016a62
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
016a62
Message-Id: <1542777026-2788-2-git-send-email-liq3ea@gmail.com>
016a62
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
016a62
(cherry picked from commit 6912bb0b3d3b140c70d8cdfd2dff77f9890d7f12)
016a62
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
016a62
---
016a62
 hw/nvram/fw_cfg.c | 35 +++++++++++++----------------------
016a62
 vl.c              |  2 +-
016a62
 2 files changed, 14 insertions(+), 23 deletions(-)
016a62
016a62
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
016a62
index d35ac7b..d7185ea 100644
016a62
--- a/hw/nvram/fw_cfg.c
016a62
+++ b/hw/nvram/fw_cfg.c
016a62
@@ -117,47 +117,38 @@ error:
016a62
 
016a62
 static void fw_cfg_bootsplash(FWCfgState *s)
016a62
 {
016a62
-    int boot_splash_time = -1;
016a62
     const char *boot_splash_filename = NULL;
016a62
-    char *p;
016a62
+    const char *boot_splash_time = NULL;
016a62
     char *filename, *file_data;
016a62
     gsize file_size;
016a62
     int file_type;
016a62
-    const char *temp;
016a62
 
016a62
     /* get user configuration */
016a62
     QemuOptsList *plist = qemu_find_opts("boot-opts");
016a62
     QemuOpts *opts = QTAILQ_FIRST(&plist->head);
016a62
-    if (opts != NULL) {
016a62
-        temp = qemu_opt_get(opts, "splash");
016a62
-        if (temp != NULL) {
016a62
-            boot_splash_filename = temp;
016a62
-        }
016a62
-        temp = qemu_opt_get(opts, "splash-time");
016a62
-        if (temp != NULL) {
016a62
-            p = (char *)temp;
016a62
-            boot_splash_time = strtol(p, &p, 10);
016a62
-        }
016a62
-    }
016a62
+    boot_splash_filename = qemu_opt_get(opts, "splash");
016a62
+    boot_splash_time = qemu_opt_get(opts, "splash-time");
016a62
 
016a62
     /* insert splash time if user configurated */
016a62
-    if (boot_splash_time >= 0) {
016a62
+    if (boot_splash_time) {
016a62
+        int64_t bst_val = qemu_opt_get_number(opts, "splash-time", -1);
016a62
         /* validate the input */
016a62
-        if (boot_splash_time > 0xffff) {
016a62
-            error_report("splash time is big than 65535, force it to 65535.");
016a62
-            boot_splash_time = 0xffff;
016a62
+        if (bst_val < 0 || bst_val > 0xffff) {
016a62
+            error_report("splash-time is invalid,"
016a62
+                         "it should be a value between 0 and 65535");
016a62
+            exit(1);
016a62
         }
016a62
         /* use little endian format */
016a62
-        qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time & 0xff);
016a62
-        qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time >> 8) & 0xff);
016a62
+        qemu_extra_params_fw[0] = (uint8_t)(bst_val & 0xff);
016a62
+        qemu_extra_params_fw[1] = (uint8_t)((bst_val >> 8) & 0xff);
016a62
         fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
016a62
     }
016a62
 
016a62
     /* insert splash file if user configurated */
016a62
-    if (boot_splash_filename != NULL) {
016a62
+    if (boot_splash_filename) {
016a62
         filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
016a62
         if (filename == NULL) {
016a62
-            error_report("failed to find file '%s'.", boot_splash_filename);
016a62
+            error_report("failed to find file '%s'", boot_splash_filename);
016a62
             return;
016a62
         }
016a62
 
016a62
diff --git a/vl.c b/vl.c
016a62
index c778594..e2212f5 100644
016a62
--- a/vl.c
016a62
+++ b/vl.c
016a62
@@ -364,7 +364,7 @@ static QemuOptsList qemu_boot_opts = {
016a62
             .type = QEMU_OPT_STRING,
016a62
         }, {
016a62
             .name = "splash-time",
016a62
-            .type = QEMU_OPT_STRING,
016a62
+            .type = QEMU_OPT_NUMBER,
016a62
         }, {
016a62
             .name = "reboot-timeout",
016a62
             .type = QEMU_OPT_STRING,
016a62
-- 
016a62
1.8.3.1
016a62