mokutil/0004-Fix-leak-of-fd-in-mok_get_variable.patch
Chenxi Mao 05417e978e Upgrade mokutil to 0.6.0
SBAT revocation update support delivered in mokutil 0.6.0
as well as shim-15.6 invoke "mokutil --set-sbat-policy latest"
during the post script installation stage.
So upgrade the version to 0.6.0 to make sure shim-15.6 can be
upgraded smoothly.

On the other hand, there are 4 patches delivered after 0.6.0 release
to fix some bugs, apply these patches as well.

*e498f64 Fix leak of fd in mok_get_variable()
*d978c18 Fix leak of list in delete_data_from_req_var()
*04791c2 mokutil bugfix: del unused opt "-s"
*82694cb Show usage instead of aborting on bad flags

Git-commit: e498f6460ff5aea6a7cd61a33087d03e88a2f52a
Git-commit: d978c18f61b877afaab45a82d260b525423b8248
Git-commit: 04791c29e198b18808bca519267e31c8d3786a08
Git-commit: 82694cb1ce3b29c3705c25ae4cea3d07fe57b558
Link: https://github.com/lcp/mokutil/
Signed-off-by: Chenxi Mao <chenxi.mao@suse.com>
2022-06-29 20:11:44 +08:00

73 lines
1.3 KiB
Diff

From e498f6460ff5aea6a7cd61a33087d03e88a2f52a Mon Sep 17 00:00:00 2001
From: Robbie Harwood <rharwood@redhat.com>
Date: Thu, 2 Jun 2022 13:00:22 -0400
Subject: [PATCH 4/5] Fix leak of fd in mok_get_variable()
On success, it was never closed. Refactor the code to use a single
egress path so its closure is clear.
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
---
src/util.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/src/util.c b/src/util.c
index 6cd0302..f7fc033 100644
--- a/src/util.c
+++ b/src/util.c
@@ -57,22 +57,21 @@ mok_get_variable(const char *name, uint8_t **datap, size_t *data_sizep)
return fd;
rc = fstat(fd, &sb);
- if (rc < 0) {
-err_close:
- close(fd);
- return rc;
- }
+ if (rc < 0)
+ goto done;
if (sb.st_size == 0) {
errno = ENOENT;
rc = -1;
- goto err_close;
+ goto done;
}
bufsz = sb.st_size;
buf = calloc(1, bufsz);
- if (!buf)
- goto err_close;
+ if (!buf) {
+ rc = -1;
+ goto done;
+ }
while (pos < bufsz) {
ssz = read(fd, &buf[pos], bufsz - pos);
@@ -82,15 +81,18 @@ err_close:
errno == EINTR)
continue;
free(buf);
- goto err_close;
+ rc = -1;
+ goto done;
}
pos += ssz;
}
*datap = buf;
*data_sizep = pos;
-
- return 0;
+ rc = 0;
+done:
+ close(fd);
+ return rc;
}
MokListNode*
--
2.33.0