qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Bibo Mao" <maobibo@loongson.cn>,
	"Kashyap Chamarthy" <kchamart@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Song Gao" <gaosong@loongson.cn>,
	"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	qemu-riscv@nongnu.org,
	"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
	"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
	"Weiwei Li" <liwei1518@gmail.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>
Subject: [PATCH v3 3/6] hw/uefi: fix error handling in uefi_vars_json_load
Date: Wed, 19 Mar 2025 15:11:55 +0100	[thread overview]
Message-ID: <20250319141159.1461621-4-kraxel@redhat.com> (raw)
In-Reply-To: <20250319141159.1461621-1-kraxel@redhat.com>

Catch lseek errors.  Return on read errors.

Fixes: CID 1593154
Fixes: CID 1593157
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/uefi/var-service-json.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/hw/uefi/var-service-json.c b/hw/uefi/var-service-json.c
index f1c20a6b8c1e..ad3462cd1557 100644
--- a/hw/uefi/var-service-json.c
+++ b/hw/uefi/var-service-json.c
@@ -214,7 +214,7 @@ void uefi_vars_json_load(uefi_vars_state *uv, Error **errp)
     QObject *qobj;
     Visitor *v;
     char *str;
-    size_t len;
+    ssize_t len;
     int rc;
 
     if (uv->jsonfd == -1) {
@@ -222,7 +222,12 @@ void uefi_vars_json_load(uefi_vars_state *uv, Error **errp)
     }
 
     len = lseek(uv->jsonfd, 0, SEEK_END);
+    if (len < 0) {
+        warn_report("%s: lseek error", __func__);
+        return;
+    }
     if (len == 0) {
+        /* empty file */
         return;
     }
 
@@ -231,6 +236,8 @@ void uefi_vars_json_load(uefi_vars_state *uv, Error **errp)
     rc = read(uv->jsonfd, str, len);
     if (rc != len) {
         warn_report("%s: read error", __func__);
+        g_free(str);
+        return;
     }
     str[len] = 0;
 
-- 
2.48.1



  parent reply	other threads:[~2025-03-19 14:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-19 14:11 [PATCH v3 0/6] [for-10.0] hw/uefi: some bugfixes Gerd Hoffmann
2025-03-19 14:11 ` [PATCH v3 1/6] hw/uefi: flush variable store to disk in post load Gerd Hoffmann
2025-03-19 14:11 ` [PATCH v3 2/6] hw/uefi: fix error handling in uefi_vars_json_save Gerd Hoffmann
2025-03-19 14:11 ` Gerd Hoffmann [this message]
2025-03-19 14:11 ` [PATCH v3 4/6] hw/uefi-vars-sysbus: allow for riscv virt Gerd Hoffmann
2025-03-19 14:22   ` Daniel P. Berrangé
2025-03-19 15:04   ` Daniel Henrique Barboza
2025-03-19 14:11 ` [PATCH v3 5/6] hw/uefi-vars-sysbus: allow for loongarch virt Gerd Hoffmann
2025-03-19 14:22   ` Daniel P. Berrangé
2025-03-19 14:11 ` [PATCH v3 6/6] docs/firmware: add feature flag for host uefi variable store Gerd Hoffmann
2025-03-19 14:21   ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250319141159.1461621-4-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=alistair.francis@wdc.com \
    --cc=berrange@redhat.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=gaosong@loongson.cn \
    --cc=jiaxun.yang@flygoat.com \
    --cc=kchamart@redhat.com \
    --cc=liwei1518@gmail.com \
    --cc=maobibo@loongson.cn \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=zhiwei_liu@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).