From patchwork Wed Nov 21 05:10:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10691943 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6C0414BD for ; Wed, 21 Nov 2018 05:14:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A3B02B6DB for ; Wed, 21 Nov 2018 05:14:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D7012B6EB; Wed, 21 Nov 2018 05:14:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2BACA2B6DB for ; Wed, 21 Nov 2018 05:14:06 +0000 (UTC) Received: from localhost ([::1]:37259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPKpx-0006st-Fz for patchwork-qemu-devel@patchwork.kernel.org; Wed, 21 Nov 2018 00:14:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPKmd-0003x2-Gq for qemu-devel@nongnu.org; Wed, 21 Nov 2018 00:10:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPKmc-0002s7-KR for qemu-devel@nongnu.org; Wed, 21 Nov 2018 00:10:39 -0500 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:44625) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gPKmc-0002rL-Eq for qemu-devel@nongnu.org; Wed, 21 Nov 2018 00:10:38 -0500 Received: by mail-pl1-x643.google.com with SMTP id s5-v6so3680450plq.11 for ; Tue, 20 Nov 2018 21:10:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=puXFQ7OfKzb+VLLxifuz4MhCgujjxYyxi/iu7h5V8kU=; b=irOaeTzreXMHkCNcVFYRl2Uq0Ab5Wf91bQczjObJdw3MMydKPmIPB2y03P5MOJaavD p9o9Ya1PW0BF3lSIzayCdT2uiEr1CDRzwj1nKmu4N6IKHJPxBR//5lup4nAxCqSsZwSY Hswk8gi7Z+YnrPVxaVAqj6JK6n4z9nwNAa6W3cE2aV63Ns4m79PtuaLVFg0PfcrRQBIv 5kKjIDDt7KwqHrZ+QFUkz8QYHniPlRYPYXg303KZAVz6344E2zL/Gdph+YZcF8NJllVE 5MVG/VbT+qoUWpTatqt85AlCcVq9Fa8GcgXfwkx9CNjF8wPGvew0A9eBBTGJS7ZGsl2u SYMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=puXFQ7OfKzb+VLLxifuz4MhCgujjxYyxi/iu7h5V8kU=; b=Gf7mzk+o5+LRj7eTgsIWNyhYkCrw845V764C4zUjmQfLtbHcbchvYng7v6C1+NWW4B l+zeciycSSOsLSpyboWK7xOqQ6pNA/RP7c8/glgGEARyKvJP+urTTPfhXR6CxuEkirfT D7yijXVh9J/pKZevl3sbpSZ4eQmhVr3mUfAFhTNjJqhbfywxWIp/btIDLGHFi8xHTOnV QeCc/cy/dTK9/+66JZoLtO28Yr0TYUOJOZLyaxiTuL0o3Y7d30ahHIaQNBu1qVUKnbYz sqPapLhaGhJcKLrPNzYO4IehAq0A7VnQBMD7PIxdfn2pxUD/5NlpSPv0MpIXeLHvTKLK 5DxA== X-Gm-Message-State: AA+aEWbLXHyi+vAg+adPY/ghIzEuYcEK7xKYGaw/CbdgKEeWz5emxj7h Z+D4gkh5p6CMAnFvd1q12Fc= X-Google-Smtp-Source: AFSGD/UKWHp9vHuewxWTE0yV95b9wJ3I+O/sjzACnGD9Hd8vHNU2bCPdQghlbL2ygRVr0EdxxUdwtA== X-Received: by 2002:a65:6215:: with SMTP id d21mr4602323pgv.289.1542777037551; Tue, 20 Nov 2018 21:10:37 -0800 (PST) Received: from localhost.localdomain.localdomain ([103.129.255.252]) by smtp.gmail.com with ESMTPSA id b62-v6sm52846616pfa.159.2018.11.20.21.10.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 21:10:37 -0800 (PST) From: Li Qiang To: armbru@redhat.com, pbonzini@redhat.com, kraxel@redhat.com, lersek@redhat.com, philmd@redhat.com Date: Tue, 20 Nov 2018 21:10:24 -0800 Message-Id: <1542777026-2788-2-git-send-email-liq3ea@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1542777026-2788-1-git-send-email-liq3ea@gmail.com> References: <1542777026-2788-1-git-send-email-liq3ea@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::643 Subject: [Qemu-devel] [PATCH v2 1/3] fw_cfg: fix -boot bootsplash error checking X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP fw_cfg_bootsplash() gets option parameter "splash-time" with qemu_opt_get(), then converts it to an integer by hand. It neglects to check that conversion for errors. This is needlessly complicated and error-prone. But as "splash-time not specified" is not the same as "splash-time=T" for any T, we need use qemu_opt_get() to check if splash time exists. This patch also make the qemu exit when finding or loading splash file failed. Signed-off-by: Li Qiang Reviewed-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daudé --- v1->v2: drop error_report when read_splashfile() fails hw/nvram/fw_cfg.c | 35 +++++++++++++---------------------- vl.c | 2 +- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 946f765f7f..83d66818f6 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -118,47 +118,38 @@ error: static void fw_cfg_bootsplash(FWCfgState *s) { - int boot_splash_time = -1; const char *boot_splash_filename = NULL; - char *p; + const char *boot_splash_time = NULL; char *filename, *file_data; gsize file_size; int file_type; - const char *temp; /* get user configuration */ QemuOptsList *plist = qemu_find_opts("boot-opts"); QemuOpts *opts = QTAILQ_FIRST(&plist->head); - if (opts != NULL) { - temp = qemu_opt_get(opts, "splash"); - if (temp != NULL) { - boot_splash_filename = temp; - } - temp = qemu_opt_get(opts, "splash-time"); - if (temp != NULL) { - p = (char *)temp; - boot_splash_time = strtol(p, &p, 10); - } - } + boot_splash_filename = qemu_opt_get(opts, "splash"); + boot_splash_time = qemu_opt_get(opts, "splash-time"); /* insert splash time if user configurated */ - if (boot_splash_time >= 0) { + if (boot_splash_time) { + int64_t bst_val = qemu_opt_get_number(opts, "splash-time", -1); /* validate the input */ - if (boot_splash_time > 0xffff) { - error_report("splash time is big than 65535, force it to 65535."); - boot_splash_time = 0xffff; + if (bst_val < 0 || bst_val > 0xffff) { + error_report("splash-time is invalid," + "it should be a value between 0 and 65535"); + exit(1); } /* use little endian format */ - qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time & 0xff); - qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time >> 8) & 0xff); + qemu_extra_params_fw[0] = (uint8_t)(bst_val & 0xff); + qemu_extra_params_fw[1] = (uint8_t)((bst_val >> 8) & 0xff); fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2); } /* insert splash file if user configurated */ - if (boot_splash_filename != NULL) { + if (boot_splash_filename) { filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename); if (filename == NULL) { - error_report("failed to find file '%s'.", boot_splash_filename); + error_report("failed to find file '%s'", boot_splash_filename); return; } diff --git a/vl.c b/vl.c index fa25d1ae2d..96ac0ddcf6 100644 --- a/vl.c +++ b/vl.c @@ -336,7 +336,7 @@ static QemuOptsList qemu_boot_opts = { .type = QEMU_OPT_STRING, }, { .name = "splash-time", - .type = QEMU_OPT_STRING, + .type = QEMU_OPT_NUMBER, }, { .name = "reboot-timeout", .type = QEMU_OPT_STRING,