]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
hw/uefi: fix error handling in uefi_vars_json_load
authorGerd Hoffmann <kraxel@redhat.com>
Wed, 19 Mar 2025 14:11:55 +0000 (15:11 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Fri, 21 Mar 2025 11:00:38 +0000 (12:00 +0100)
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

index f1c20a6b8c1e2edbe864325b7bdeda5231bcfe96..ad3462cd15575d992b8a159d3f47edf8b85014f4 100644 (file)
@@ -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;