1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/efivar/posix-compat.patch.musl
3 # Copyright (C) 2023 The T2 SDE Project
5 # This Copyright note is generated by scripts/Create-CopyPatch,
6 # more information can be found in the files COPYING and README.
8 # This patch file is dual-licensed. It is available under the license the
9 # patched project is licensed under, as long as it is an OpenSource license
10 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
11 # of the GNU General Public License version 2 as used by the T2 SDE.
12 # --- T2-COPYRIGHT-NOTE-END ---
14 From cece3ffd5be2f8641eb694513f2b73e5eb97ffd3 Mon Sep 17 00:00:00 2001
15 From: Natanael Copa <ncopa@alpinelinux.org>
16 Date: Fri, 28 Jan 2022 12:13:30 +0100
17 Subject: [PATCH 1/2] efisecdb: fix build with musl libc
19 Refactor code to use POSIX atexit(3) instead of the GNU specific
24 Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
27 src/efisecdb.c | 68 +++++++++++++++++++-------------------------------
28 2 files changed, 26 insertions(+), 44 deletions(-)
30 diff --git a/src/compiler.h b/src/compiler.h
31 index e2f18f0b..d95fb014 100644
38 -#include <sys/cdefs.h>
40 /* GCC version checking borrowed from glibc. */
41 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
42 # define GNUC_PREREQ(maj,min) \
43 diff --git a/src/efisecdb.c b/src/efisecdb.c
44 index f8823737..6bd5ad90 100644
49 extern int optind, opterr, optopt;
51 +static efi_secdb_t *secdb = NULL;
52 +static list_t infiles;
53 +static list_t actions;
57 efi_secdb_type_t algorithm;
58 @@ -187,12 +191,11 @@ add_action(list_t *list, action_type_t action_type, const efi_guid_t *owner,
62 -free_actions(int status UNUSED, void *actionsp)
65 - list_t *actions = (list_t *)actionsp;
68 - for_each_action_safe(pos, tmp, actions) {
69 + for_each_action_safe(pos, tmp, &actions) {
70 action_t *action = list_entry(pos, action_t, list);
72 list_del(&action->list);
73 @@ -202,12 +205,11 @@ free_actions(int status UNUSED, void *actionsp)
77 -free_infiles(int status UNUSED, void *infilesp)
80 - list_t *infiles = (list_t *)infilesp;
83 - for_each_ptr_safe(pos, tmp, infiles) {
84 + for_each_ptr_safe(pos, tmp, &infiles) {
85 ptrlist_t *entry = list_entry(pos, ptrlist_t, list);
87 list_del(&entry->list);
88 @@ -216,27 +218,12 @@ free_infiles(int status UNUSED, void *infilesp)
92 -maybe_free_secdb(int status UNUSED, void *voidp)
93 +maybe_free_secdb(void)
95 - efi_secdb_t **secdbp = (efi_secdb_t **)voidp;
97 - if (secdbp == NULL || *secdbp == NULL)
101 - efi_secdb_free(*secdbp);
105 -maybe_do_unlink(int status, void *filep)
107 - char **file = (char **)filep;
111 - if (file == NULL || *file == NULL)
115 + efi_secdb_free(secdb);
119 @@ -323,15 +310,6 @@ parse_input_files(list_t *infiles, char **outfile, efi_secdb_t **secdb,
124 - * These need to be static globals so that they're not on main's stack when
127 -static efi_secdb_t *secdb = NULL;
128 -static list_t infiles;
129 -static list_t actions;
130 -static char *outfile = NULL;
133 main(int argc, char *argv[])
135 @@ -351,6 +329,7 @@ main(int argc, char *argv[])
136 bool do_sort_data = false;
137 bool sort_descending = false;
139 + char *outfile = NULL;
141 const char sopts[] = ":aAc:dfg:h:i:Lo:rs:t:v?";
142 const struct option lopts[] = {
143 @@ -376,10 +355,9 @@ main(int argc, char *argv[])
144 INIT_LIST_HEAD(&infiles);
145 INIT_LIST_HEAD(&actions);
147 - on_exit(free_actions, &actions);
148 - on_exit(free_infiles, &infiles);
149 - on_exit(maybe_free_secdb, &secdb);
150 - on_exit(maybe_do_unlink, &outfile);
151 + atexit(free_actions);
152 + atexit(free_infiles);
153 + atexit(maybe_free_secdb);
156 * parse the command line.
157 @@ -587,24 +565,30 @@ main(int argc, char *argv[])
158 outfd = open(outfile, flags, 0600);
160 char *tmpoutfile = outfile;
161 - if (errno == EEXIST)
163 + if (errno != EEXIST)
165 err(1, "could not open \"%s\"", tmpoutfile);
168 rc = ftruncate(outfd, 0);
172 err(1, "could not truncate output file \"%s\"", outfile);
177 rc = efi_secdb_realize(secdb, &output, &size);
181 secdb_err(1, "could not realize signature list");
184 rc = write(outfd, output, size);
188 err(1, "could not write signature list");
194 From df09b472419466987f2f30176dd00937e640aa9a Mon Sep 17 00:00:00 2001
195 From: Natanael Copa <ncopa@alpinelinux.org>
196 Date: Fri, 28 Jan 2022 12:29:00 +0100
197 Subject: [PATCH 2/2] efisecdb: do not free optarg
199 The *outfile passed to parse_input_files can only be either set to
200 optarg or be NULL. optarg should not be free'd and NULL does not need
203 Since we no longer use on_exit to unlink outfile we also don't need to
204 set *outfile to NULL.
206 Fixes commit d91787035bc1 (efisecdb: add efisecdb)
208 Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
210 src/efisecdb.c | 7 ++-----
211 1 file changed, 2 insertions(+), 5 deletions(-)
213 diff --git a/src/efisecdb.c b/src/efisecdb.c
214 index 6bd5ad90..70fa1847 100644
217 @@ -255,8 +255,7 @@ list_guids(void)
221 -parse_input_files(list_t *infiles, char **outfile, efi_secdb_t **secdb,
223 +parse_input_files(list_t *infiles, efi_secdb_t **secdb, bool dump)
227 @@ -297,8 +296,6 @@ parse_input_files(list_t *infiles, char **outfile, efi_secdb_t **secdb,
236 @@ -528,7 +525,7 @@ main(int argc, char *argv[])
237 efi_secdb_set_bool(secdb, EFI_SECDB_SORT_DATA, do_sort_data);
238 efi_secdb_set_bool(secdb, EFI_SECDB_SORT_DESCENDING, sort_descending);
240 - status = parse_input_files(&infiles, &outfile, &secdb, dump);
241 + status = parse_input_files(&infiles, &secdb, dump);
243 for_each_action_safe(pos, tmp, &actions) {
244 action_t *action = list_entry(pos, action_t, list);