aports/main/efitools/003-fix-wchar_t.patch
2024-08-09 14:10:32 +00:00

92 lines
2.7 KiB
Diff

efitools expects 16-bit wchat_t, while musl always treats wchar_t as 32-bit.
So we replace the wchar_t type with uint16_t.
But we keep "-fshort-wchar" cflag in the Make.rules file.
Because efitools uses L-prefixed strings to call methods imported from gnu-efi.
These methods require 16-bit strings.
Reserve "-fshort-wchar" to generate 16-bit L-prefixed strings instead of 32-bit.
---
diff --git a/cert-to-efi-hash-list.c b/cert-to-efi-hash-list.c
index 8a5468a..c6b1e8e 100644
--- a/cert-to-efi-hash-list.c
+++ b/cert-to-efi-hash-list.c
@@ -23,7 +23,6 @@
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
-#include <wchar.h>
#include <openssl/pem.h>
#include <openssl/err.h>
diff --git a/flash-var.c b/flash-var.c
index aa10ae6..3ff6c7e 100644
--- a/flash-var.c
+++ b/flash-var.c
@@ -46,7 +46,7 @@ main(int argc, char *argv[])
| EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS;
int flashfile, varfile, i, offset, varlen, varfilesize, listvars = 0;
const int chunk = 8;
- wchar_t var[128];
+ uint16_t var[128];
struct stat st;
EFI_GUID *owner = NULL, guid;
EFI_TIME timestamp;
@@ -88,7 +88,7 @@ main(int argc, char *argv[])
/* copy to wchar16_t including trailing zero */
for (i = 0; i < strlen(argv[2]) + 1; i++)
var[i] = argv[2][i];
- varlen = i*2; /* size of storage including zero */
+ varlen = i*sizeof(var[0]); /* size of storage including zero */
if (!owner)
owner = get_owner_guid(argv[2]);
diff --git a/hash-to-efi-sig-list.c b/hash-to-efi-sig-list.c
index 4b69026..dbbc4f1 100644
--- a/hash-to-efi-sig-list.c
+++ b/hash-to-efi-sig-list.c
@@ -21,7 +21,6 @@
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
-#include <wchar.h>
#include <PeImage.h> /* for ALIGN_VALUE */
#include <sha256.h>
diff --git a/sign-efi-sig-list.c b/sign-efi-sig-list.c
index 94bd7d4..27abc17 100644
--- a/sign-efi-sig-list.c
+++ b/sign-efi-sig-list.c
@@ -21,7 +21,6 @@
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
-#include <wchar.h>
#include <variables.h>
#include <guid.h>
@@ -73,7 +72,7 @@ main(int argc, char *argv[])
sigsize;
EFI_GUID vendor_guid;
struct stat st;
- wchar_t var[256];
+ uint16_t var[256];
UINT32 attributes = EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
@@ -191,14 +190,11 @@ main(int argc, char *argv[])
timestamp.Month, timestamp.Day, timestamp.Hour, timestamp.Minute,
timestamp.Second);
- /* Warning: don't use any glibc wchar functions. We're building
- * with -fshort-wchar which breaks the glibc ABI */
i = 0;
do {
var[i] = str[i];
} while (str[i++] != '\0');
-
- varlen = (i - 1)*sizeof(wchar_t);
+ varlen = (i - 1)*sizeof(var[0]);
int fdefifile = open(efifile, O_RDONLY);
if (fdefifile == -1) {