summary refs log tree commit diff stats
path: root/hw/uefi/var-service-json.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2025-03-19 15:11:55 +0100
committerGerd Hoffmann <kraxel@redhat.com>2025-03-21 12:00:38 +0100
commit761d0b5fb7e0f0a6a36c5fc449c6feda2b78af79 (patch)
tree762c87bf7eebc08f5535cf3cea8e4044f6a736d2 /hw/uefi/var-service-json.c
parentae24cf139ba681f8ce3dc809f3f1119b16c73043 (diff)
downloadfocaccia-qemu-761d0b5fb7e0f0a6a36c5fc449c6feda2b78af79.tar.gz
focaccia-qemu-761d0b5fb7e0f0a6a36c5fc449c6feda2b78af79.zip
hw/uefi: fix error handling in uefi_vars_json_load
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>
Diffstat (limited to 'hw/uefi/var-service-json.c')
-rw-r--r--hw/uefi/var-service-json.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/hw/uefi/var-service-json.c b/hw/uefi/var-service-json.c
index f1c20a6b8c..ad3462cd15 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;