aboutsummaryrefslogtreecommitdiff
path: root/hw/uefi/var-service-json.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2025-03-19 15:11:54 +0100
committerGerd Hoffmann <kraxel@redhat.com>2025-03-21 12:00:38 +0100
commitae24cf139ba681f8ce3dc809f3f1119b16c73043 (patch)
tree7d682ab8e1eb34dae4b6272469c0305137a721d8 /hw/uefi/var-service-json.c
parent560429fd746adf04b57237c3c4a38ecfd906c592 (diff)
downloadqemu-ae24cf139ba681f8ce3dc809f3f1119b16c73043.zip
qemu-ae24cf139ba681f8ce3dc809f3f1119b16c73043.tar.gz
qemu-ae24cf139ba681f8ce3dc809f3f1119b16c73043.tar.bz2
hw/uefi: fix error handling in uefi_vars_json_save
Catch lseek errors. Return on errors. Use autoptr for the GString to simplify cleanup. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Message-ID: <20250319141159.1461621-3-kraxel@redhat.com>
Diffstat (limited to 'hw/uefi/var-service-json.c')
-rw-r--r--hw/uefi/var-service-json.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/hw/uefi/var-service-json.c b/hw/uefi/var-service-json.c
index 761082c..f1c20a6 100644
--- a/hw/uefi/var-service-json.c
+++ b/hw/uefi/var-service-json.c
@@ -178,7 +178,7 @@ void uefi_vars_json_init(uefi_vars_state *uv, Error **errp)
void uefi_vars_json_save(uefi_vars_state *uv)
{
- GString *gstr;
+ g_autoptr(GString) gstr = NULL;
int rc;
if (uv->jsonfd == -1) {
@@ -187,18 +187,25 @@ void uefi_vars_json_save(uefi_vars_state *uv)
gstr = uefi_vars_to_json(uv);
- lseek(uv->jsonfd, 0, SEEK_SET);
+ rc = lseek(uv->jsonfd, 0, SEEK_SET);
+ if (rc < 0) {
+ warn_report("%s: lseek error", __func__);
+ return;
+ }
+
rc = ftruncate(uv->jsonfd, 0);
if (rc != 0) {
warn_report("%s: ftruncate error", __func__);
+ return;
}
+
rc = write(uv->jsonfd, gstr->str, gstr->len);
if (rc != gstr->len) {
warn_report("%s: write error", __func__);
+ return;
}
- fsync(uv->jsonfd);
- g_string_free(gstr, true);
+ fsync(uv->jsonfd);
}
void uefi_vars_json_load(uefi_vars_state *uv, Error **errp)