From e7c8902e7cb8800e427fed29be2b0f017cfe4291 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Mon, 30 Dec 2024 13:46:48 +0000 Subject: [PATCH] Avoid integer promotion bug in memory functions Based on: rhboot/gnu-efi@7cfefa091903bfde6160f94f52ac66c51f07989f Co-authored-by: Peter Jones Signed-off-by: Callum Farmer --- Make.defaults | 4 ++-- lib/runtime/efirtlib.c | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Make.defaults b/Make.defaults index 1347aca..2322c19 100755 --- a/Make.defaults +++ b/Make.defaults @@ -260,9 +260,9 @@ CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \ -fno-strict-aliasing \ -ffreestanding -fno-stack-protector else -CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Wno-pointer-sign -Werror \ +CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \ -fno-strict-aliasing \ - -ffreestanding -fno-stack-protector -fno-stack-check \ + -ffreestanding -fno-stack-protector \ $(if $(findstring 0,$(USING_CLANG)),-Wno-error=maybe-uninitialized,) \ $(if $(findstring 0,$(USING_CLANG)),-fno-merge-all-constants,) endif diff --git a/lib/runtime/efirtlib.c b/lib/runtime/efirtlib.c index daa1d6a..b574f55 100644 --- a/lib/runtime/efirtlib.c +++ b/lib/runtime/efirtlib.c @@ -30,7 +30,7 @@ RtZeroMem ( IN UINTN Size ) { - INT8 *pt; + UINT8 *pt; pt = Buffer; while (Size--) { @@ -50,7 +50,7 @@ RtSetMem ( IN UINT8 Value ) { - INT8 *pt; + UINT8 *pt; pt = Buffer; while (Size--) { @@ -70,8 +70,10 @@ RtCopyMem ( IN UINTN len ) { - CHAR8 *d = (CHAR8*)Dest; - CHAR8 *s = (CHAR8*)Src; + UINT8 *d, *s; + + d = Dest; + s = Src; if (d == NULL || s == NULL || s == d) return; @@ -118,7 +120,11 @@ RtCompareMem ( IN UINTN len ) { - CONST CHAR8 *d = Dest, *s = Src; + CONST UINT8 *d, *s; + + d = Dest; + s = Src; + while (len--) { if (*d != *s) { return *d - *s; @@ -157,14 +163,14 @@ Routine Description: --*/ { - INT32 *g1, *g2, r; + UINT32 *g1, *g2, r; // // Compare 32 bits at a time // - g1 = (INT32 *) Guid1; - g2 = (INT32 *) Guid2; + g1 = (UINT32*)Guid1; + g2 = (UINT32*)Guid2; r = g1[0] - g2[0]; r |= g1[1] - g2[1];