cryptospore / rpms / qemu-kvm

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