From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
"Kashyap Chamarthy" <kchamart@redhat.com>,
"Weiwei Li" <liwei1518@gmail.com>,
"Bibo Mao" <maobibo@loongson.cn>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
qemu-riscv@nongnu.org, "Gerd Hoffmann" <kraxel@redhat.com>,
"Alistair Francis" <alistair.francis@wdc.com>,
"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
"Song Gao" <gaosong@loongson.cn>,
"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PULL 3/6] hw/uefi: fix error handling in uefi_vars_json_load
Date: Fri, 21 Mar 2025 13:36:01 +0100 [thread overview]
Message-ID: <20250321123604.2126923-4-kraxel@redhat.com> (raw)
In-Reply-To: <20250321123604.2126923-1-kraxel@redhat.com>
Catch lseek errors. Return on read errors.
Fixes: CID 1593154
Fixes: CID 1593157
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-ID: <20250319141159.1461621-4-kraxel@redhat.com>
---
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.49.0
next prev parent reply other threads:[~2025-03-21 12:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-21 12:35 [PULL 0/6] Uefi 20250321 patches Gerd Hoffmann
2025-03-21 12:35 ` [PULL 1/6] hw/uefi: flush variable store to disk in post load Gerd Hoffmann
2025-03-21 12:36 ` [PULL 2/6] hw/uefi: fix error handling in uefi_vars_json_save Gerd Hoffmann
2025-03-21 12:36 ` Gerd Hoffmann [this message]
2025-03-21 12:36 ` [PULL 4/6] hw/uefi-vars-sysbus: allow for riscv virt Gerd Hoffmann
2025-03-21 12:36 ` [PULL 5/6] hw/uefi-vars-sysbus: allow for loongarch virt Gerd Hoffmann
2025-03-21 12:36 ` [PULL 6/6] docs/firmware: add feature flag for host uefi variable store Gerd Hoffmann
2025-03-23 22:29 ` [PULL 0/6] Uefi 20250321 patches Stefan Hajnoczi
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=20250321123604.2126923-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).