efivar/0034-Try-to-deal-with-some-signof-char-signof-uint8_t-mad.patch
Petr Šabata 974b936917 RHEL 9.0.0 Alpha bootstrap
The content of this branch was automatically imported from Fedora ELN
with the following as its source:
https://src.fedoraproject.org/rpms/efivar#9f54d8029387895b7b1389d9a9f9e0bf476a027f
2020-10-14 23:58:29 +02:00

432 lines
15 KiB
Diff

From ba165d1482558005a16f4b44abaa1df5169727d1 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 17 Jun 2019 14:47:24 -0400
Subject: [PATCH 34/86] Try to deal with some signof(char) != signof(uint8_t)
madness.
The 3-sign "char" type in C is so so painful sometimes. This attempts
to use -funsigned-char to avoid type-casting between (uint8_t *) and
(char *) quite so much. I'm not sure it'll pay off. The fact that
"char" is something that's not ever actually the same type as "unsigned
char" or "signed char" is still the absolute worst thing.
Why do we need signed char at all again?
Signed-off-by: Peter Jones <pjones@redhat.com>
---
Make.defaults | 4 +++-
gcc.specs | 4 ++--
src/dp-acpi.c | 11 ++++++-----
src/dp-hw.c | 5 +++--
src/dp-media.c | 2 +-
src/dp-message.c | 22 +++++++++++-----------
src/dp.c | 8 +++++---
src/dp.h | 18 ++++++++++--------
src/export.c | 12 ++++++------
src/include/efivar/efivar-dp.h | 10 ++++++----
src/include/efivar/efivar.h | 4 ++--
src/ucs2.h | 6 +++---
12 files changed, 58 insertions(+), 48 deletions(-)
diff --git a/Make.defaults b/Make.defaults
index 80fd99eba71..36e922f5ba7 100644
--- a/Make.defaults
+++ b/Make.defaults
@@ -31,7 +31,9 @@ PKGS =
CPPFLAGS += -DLIBEFIVAR_VERSION=$(VERSION)
-clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member
+clang_cflags = -D_GNU_SOURCE -std=gnu11 -Wno-address-of-packed-member \
+ -funsigned-char -Wall -Wno-nonnull-compare \
+ -Werror -Wno-error=cpp
gcc_cflags = -specs=$(TOPDIR)/gcc.specs
cflags = $(CFLAGS) -I${TOPDIR}/src/include/ \
$(if $(findstring clang,$(CC)),$(clang_cflags),) \
diff --git a/gcc.specs b/gcc.specs
index d06a8e096fc..9d2b145ee6e 100644
--- a/gcc.specs
+++ b/gcc.specs
@@ -2,13 +2,13 @@
+ -D_GNU_SOURCE
*efivar_cpp_options:
- -Werror -Wall -std=gnu11 -Wextra
+ -Wall -Wno-nonnull-compare -Werror -Wno-error=cpp -std=gnu11 -Wextra -funsigned-char
*cpp_options:
+ %(efivar_cpp_options)
*cc1_options:
-+ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches
++ %(efivar_cpp_options) -Wmaybe-uninitialized -fno-merge-constants -funsigned-char -fvisibility=hidden %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches
*self_spec:
+ %{!shared:%{!static:%{!r:-pie}}} %{static:-Wl,-no-fatal-warnings -Wl,-static -static -Wl,-z,relro,-z,now} -grecord-gcc-switches
diff --git a/src/dp-acpi.c b/src/dp-acpi.c
index 2525fdfd073..02ec70eec7a 100644
--- a/src/dp-acpi.c
+++ b/src/dp-acpi.c
@@ -28,7 +28,7 @@
#include "efivar.h"
static ssize_t
-_format_acpi_adr(char *buf, size_t size,
+_format_acpi_adr(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp)
{
@@ -45,9 +45,10 @@ _format_acpi_adr(char *buf, size_t size,
format_helper(_format_acpi_adr, buf, size, off, "AcpiAdr", dp)
static ssize_t
-_format_acpi_hid_ex(char *buf, size_t size, const char *dp_type UNUSED,
- const_efidp dp,
- const char *hidstr, const char *cidstr, const char *uidstr)
+_format_acpi_hid_ex(unsigned char *buf, size_t size,
+ const char *dp_type UNUSED, const_efidp dp,
+ const char *hidstr, const char *cidstr,
+ const char *uidstr)
{
ssize_t off = 0;
@@ -98,7 +99,7 @@ _format_acpi_hid_ex(char *buf, size_t size, const char *dp_type UNUSED,
hidstr, cidstr, uidstr)
ssize_t
-_format_acpi_dn(char *buf, size_t size, const_efidp dp)
+_format_acpi_dn(unsigned char *buf, size_t size, const_efidp dp)
{
ssize_t off = 0;
const char *hidstr = NULL;
diff --git a/src/dp-hw.c b/src/dp-hw.c
index 1fe0f66e871..28998316d9d 100644
--- a/src/dp-hw.c
+++ b/src/dp-hw.c
@@ -26,7 +26,8 @@
#include "efivar.h"
ssize_t
-format_edd10_guid(char *buf, size_t size, const char *dp_type, const_efidp dp)
+format_edd10_guid(unsigned char *buf, size_t size,
+ const char *dp_type, const_efidp dp)
{
ssize_t off = 0;
efidp_edd10 const *edd_dp = (efidp_edd10 *)dp;
@@ -36,7 +37,7 @@ format_edd10_guid(char *buf, size_t size, const char *dp_type, const_efidp dp)
}
ssize_t
-_format_hw_dn(char *buf, size_t size, const_efidp dp)
+_format_hw_dn(unsigned char *buf, size_t size, const_efidp dp)
{
efi_guid_t edd10_guid = EDD10_HARDWARE_VENDOR_PATH_GUID;
ssize_t off = 0;
diff --git a/src/dp-media.c b/src/dp-media.c
index 4728c326100..7f5d1c678ce 100644
--- a/src/dp-media.c
+++ b/src/dp-media.c
@@ -28,7 +28,7 @@
#include "efivar.h"
ssize_t
-_format_media_dn(char *buf, size_t size, const_efidp dp)
+_format_media_dn(unsigned char *buf, size_t size, const_efidp dp)
{
ssize_t off = 0;
switch (dp->subtype) {
diff --git a/src/dp-message.c b/src/dp-message.c
index b88f17fb712..d00b2ad5d67 100644
--- a/src/dp-message.c
+++ b/src/dp-message.c
@@ -28,7 +28,7 @@
#include "efivar.h"
static ssize_t
-format_ipv4_addr_helper(char *buf, size_t size, const char *dp_type,
+format_ipv4_addr_helper(unsigned char *buf, size_t size, const char *dp_type,
const uint8_t *ipaddr, int32_t port)
{
ssize_t off = 0;
@@ -40,7 +40,7 @@ format_ipv4_addr_helper(char *buf, size_t size, const char *dp_type,
}
static ssize_t
-format_ipv6_addr_helper(char *buf, size_t size, const char *dp_type,
+format_ipv6_addr_helper(unsigned char *buf, size_t size, const char *dp_type,
const uint8_t *ipaddr, int32_t port)
{
uint16_t *ip = (uint16_t *)ipaddr;
@@ -123,7 +123,7 @@ format_ipv6_addr_helper(char *buf, size_t size, const char *dp_type,
"IPv6", addr, port)
static ssize_t
-format_ip_addr_helper(char *buf, size_t size,
+format_ip_addr_helper(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
int is_ipv6, const efi_ip_addr_t *addr)
{
@@ -142,7 +142,7 @@ format_ip_addr_helper(char *buf, size_t size,
dp_type, is_ipv6, addr)
static ssize_t
-format_uart(char *buf, size_t size,
+format_uart(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp)
{
@@ -162,7 +162,7 @@ format_uart(char *buf, size_t size,
}
static ssize_t
-format_sas(char *buf, size_t size,
+format_sas(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp)
{
@@ -232,7 +232,7 @@ format_sas(char *buf, size_t size,
dp->usb_class.device_protocol)
static ssize_t
-format_usb_class(char *buf, size_t size,
+format_usb_class(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp)
{
@@ -312,7 +312,7 @@ format_usb_class(char *buf, size_t size,
}
ssize_t
-_format_message_dn(char *buf, size_t size, const_efidp dp)
+_format_message_dn(unsigned char *buf, size_t size, const_efidp dp)
{
ssize_t off = 0;
switch (dp->subtype) {
@@ -393,7 +393,7 @@ _format_message_dn(char *buf, size_t size, const_efidp dp)
struct {
efi_guid_t guid;
char label[40];
- ssize_t (*formatter)(char *buf, size_t size,
+ ssize_t (*formatter)(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp);
} subtypes[] = {
@@ -417,7 +417,7 @@ _format_message_dn(char *buf, size_t size, const_efidp dp)
.label = "" }
};
char *label = NULL;
- ssize_t (*formatter)(char *buf, size_t size,
+ ssize_t (*formatter)(unsigned char *buf, size_t size,
const char *dp_type UNUSED,
const_efidp dp) = NULL;
@@ -455,8 +455,8 @@ _format_message_dn(char *buf, size_t size, const_efidp dp)
}
case EFIDP_MSG_IPv6: {
efidp_ipv6_addr const *a = &dp->ipv6_addr;
- char *addr0 = NULL;
- char *addr1 = NULL;
+ unsigned char *addr0 = NULL;
+ unsigned char *addr1 = NULL;
ssize_t tmpoff = 0;
ssize_t sz;
diff --git a/src/dp.c b/src/dp.c
index b6eea74878c..f6a4b2ddafa 100644
--- a/src/dp.c
+++ b/src/dp.c
@@ -298,7 +298,8 @@ efidp_append_instance(const_efidp dp, const_efidp dpi, efidp *out)
}
ssize_t PUBLIC
-efidp_format_device_path(char *buf, size_t size, const_efidp dp, ssize_t limit)
+efidp_format_device_path(unsigned char *buf, size_t size, const_efidp dp,
+ ssize_t limit)
{
ssize_t off = 0;
int first = 1;
@@ -402,7 +403,8 @@ efidp_format_device_path(char *buf, size_t size, const_efidp dp, ssize_t limit)
}
ssize_t PUBLIC
-efidp_parse_device_node(char *path UNUSED, efidp out UNUSED, size_t size UNUSED)
+efidp_parse_device_node(unsigned char *path UNUSED,
+ efidp out UNUSED, size_t size UNUSED)
{
efi_error("not implented");
errno = -ENOSYS;
@@ -410,7 +412,7 @@ efidp_parse_device_node(char *path UNUSED, efidp out UNUSED, size_t size UNUSED)
}
ssize_t PUBLIC
-efidp_parse_device_path(char *path UNUSED, efidp out UNUSED,
+efidp_parse_device_path(unsigned char *path UNUSED, efidp out UNUSED,
size_t size UNUSED)
{
efi_error("not implented");
diff --git a/src/dp.h b/src/dp.h
index 33a29db0d5d..6609b0d827e 100644
--- a/src/dp.h
+++ b/src/dp.h
@@ -88,8 +88,9 @@
})
static inline ssize_t UNUSED
-format_hex_helper(char *buf, size_t size, const char *dp_type, char *separator,
- int stride, const void * const addr, const size_t len)
+format_hex_helper(unsigned char *buf, size_t size, const char *dp_type,
+ char *separator, int stride, const void * const addr,
+ const size_t len)
{
ssize_t off = 0;
for (size_t i = 0; i < len; i++) {
@@ -110,7 +111,8 @@ format_hex_helper(char *buf, size_t size, const char *dp_type, char *separator,
addr, len)
static inline ssize_t UNUSED
-format_vendor_helper(char *buf, size_t size, char *label, const_efidp dp)
+format_vendor_helper(unsigned char *buf, size_t size, char *label,
+ const_efidp dp)
{
ssize_t off = 0;
ssize_t bytes = efidp_node_size(dp)
@@ -157,11 +159,11 @@ format_vendor_helper(char *buf, size_t size, char *label, const_efidp dp)
off; \
})
-extern ssize_t _format_hw_dn(char *buf, size_t size, const_efidp dp);
-extern ssize_t _format_acpi_dn(char *buf, size_t size, const_efidp dp);
-extern ssize_t _format_message_dn(char *buf, size_t size, const_efidp dp);
-extern ssize_t _format_media_dn(char *buf, size_t size, const_efidp dp);
-extern ssize_t _format_bios_boot_dn(char *buf, size_t size, const_efidp dp);
+extern ssize_t _format_hw_dn(unsigned char *buf, size_t size, const_efidp dp);
+extern ssize_t _format_acpi_dn(unsigned char *buf, size_t size, const_efidp dp);
+extern ssize_t _format_message_dn(unsigned char *buf, size_t size, const_efidp dp);
+extern ssize_t _format_media_dn(unsigned char *buf, size_t size, const_efidp dp);
+extern ssize_t _format_bios_boot_dn(unsigned char *buf, size_t size, const_efidp dp);
#define format_helper_2(name, buf, size, off, dp) ({ \
ssize_t _sz; \
diff --git a/src/export.c b/src/export.c
index 5b11ae883cf..6b78412cce1 100644
--- a/src/export.c
+++ b/src/export.c
@@ -35,7 +35,7 @@
struct efi_variable {
uint64_t attrs;
efi_guid_t *guid;
- char *name;
+ unsigned char *name;
uint8_t *data;
size_t data_size;
};
@@ -149,7 +149,7 @@ efi_variable_import(uint8_t *data, size_t size, efi_variable_t **var_out)
ssize_t NONNULL(1) PUBLIC
efi_variable_export(efi_variable_t *var, uint8_t *data, size_t size)
{
- size_t name_len = strlen(var->name);
+ size_t name_len = strlen((char *)var->name);
size_t needed = sizeof (uint32_t) /* magic */
+ sizeof (uint32_t) /* version */
@@ -233,13 +233,13 @@ efi_variable_free(efi_variable_t *var, int free_data)
}
int NONNULL(1, 2) PUBLIC
-efi_variable_set_name(efi_variable_t *var, char *name)
+efi_variable_set_name(efi_variable_t *var, unsigned char *name)
{
var->name = name;
return 0;
}
-char PUBLIC NONNULL(1) *
+unsigned char PUBLIC NONNULL(1) *
efi_variable_get_name(efi_variable_t *var)
{
if (!var->name) {
@@ -329,10 +329,10 @@ efi_variable_realize(efi_variable_t *var)
}
uint32_t attrs = var->attrs & ATTRS_MASK;
if (attrs & EFI_VARIABLE_APPEND_WRITE) {
- return efi_append_variable(*var->guid, var->name,
+ return efi_append_variable(*var->guid, (char *)var->name,
var->data, var->data_size, attrs);
}
- return efi_set_variable(*var->guid, var->name, var->data,
+ return efi_set_variable(*var->guid, (char *)var->name, var->data,
var->data_size, attrs, 0600);
}
diff --git a/src/include/efivar/efivar-dp.h b/src/include/efivar/efivar-dp.h
index 57453548701..706d25bdebd 100644
--- a/src/include/efivar/efivar-dp.h
+++ b/src/include/efivar/efivar-dp.h
@@ -1240,10 +1240,12 @@ efidp_is_valid(const_efidp dp, ssize_t limit)
#endif
/* and now, printing and parsing */
-extern ssize_t efidp_parse_device_node(char *path, efidp out, size_t size);
-extern ssize_t efidp_parse_device_path(char *path, efidp out, size_t size);
-extern ssize_t efidp_format_device_path(char *buf, size_t size, const_efidp dp,
- ssize_t limit);
+extern ssize_t efidp_parse_device_node(unsigned char *path,
+ efidp out, size_t size);
+extern ssize_t efidp_parse_device_path(unsigned char *path,
+ efidp out, size_t size);
+extern ssize_t efidp_format_device_path(unsigned char *buf, size_t size,
+ const_efidp dp, ssize_t limit);
extern ssize_t efidp_make_vendor(uint8_t *buf, ssize_t size, uint8_t type,
uint8_t subtype, efi_guid_t vendor_guid,
void *data, size_t data_size);
diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
index caa4adf056c..729b6fe80f7 100644
--- a/src/include/efivar/efivar.h
+++ b/src/include/efivar/efivar.h
@@ -144,9 +144,9 @@ extern efi_variable_t *efi_variable_alloc(void)
__attribute__((__visibility__ ("default")));
extern void efi_variable_free(efi_variable_t *var, int free_data);
-extern int efi_variable_set_name(efi_variable_t *var, char *name)
+extern int efi_variable_set_name(efi_variable_t *var, unsigned char *name)
__attribute__((__nonnull__ (1, 2)));
-extern char *efi_variable_get_name(efi_variable_t *var)
+extern unsigned char *efi_variable_get_name(efi_variable_t *var)
__attribute__((__visibility__ ("default")))
__attribute__((__nonnull__ (1)));
diff --git a/src/ucs2.h b/src/ucs2.h
index 176f9ccac57..478de23b23f 100644
--- a/src/ucs2.h
+++ b/src/ucs2.h
@@ -47,7 +47,7 @@ ucs2size(const void *s, ssize_t limit)
}
static inline size_t UNUSED NONNULL(1)
-utf8len(uint8_t *s, ssize_t limit)
+utf8len(const unsigned char *s, ssize_t limit)
{
ssize_t i, j;
for (i = 0, j = 0; i < (limit >= 0 ? limit : i+1) && s[i] != '\0';
@@ -64,7 +64,7 @@ utf8len(uint8_t *s, ssize_t limit)
}
static inline size_t UNUSED NONNULL(1)
-utf8size(uint8_t *s, ssize_t limit)
+utf8size(const unsigned char *s, ssize_t limit)
{
size_t ret = utf8len(s,limit);
if (ret < (limit >= 0 ? (size_t)limit : ret+1))
@@ -129,7 +129,7 @@ ucs2_to_utf8(const void * const voidchars, ssize_t limit)
}
static inline ssize_t UNUSED NONNULL(4)
-utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, uint8_t *utf8)
+utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, const unsigned char *utf8)
{
ssize_t req;
ssize_t i, j;
--
2.24.1