Skip to content

Commit

Permalink
Avoid integer promotion bug in memory functions
Browse files Browse the repository at this point in the history
Based on: rhboot/gnu-efi@7cfefa0

Co-authored-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Callum Farmer <gmbr3@opensuse.org>
  • Loading branch information
gmbr3 and vathpela committed Dec 30, 2024
1 parent 456f139 commit e7c8902
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Make.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions lib/runtime/efirtlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RtZeroMem (
IN UINTN Size
)
{
INT8 *pt;
UINT8 *pt;

pt = Buffer;
while (Size--) {
Expand All @@ -50,7 +50,7 @@ RtSetMem (
IN UINT8 Value
)
{
INT8 *pt;
UINT8 *pt;

pt = Buffer;
while (Size--) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit e7c8902

Please sign in to comment.