]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern/loongarch64/dl_helper: Avoid undefined behavior when popping from an empty reloc...
authorWANG Xuerui <git@xen0n.name>
Thu, 18 May 2023 02:52:57 +0000 (10:52 +0800)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 25 May 2023 14:47:59 +0000 (16:47 +0200)
The return value of grub_loongarch64_stack_pop() is unsigned, so -1 should
not be used in the first place. Replacing with 0 is enough to avoid the
UB in this edge case.

Technically though, proper error handling is needed throughout the
management of the reloc stack, so no unexpected behavior will happen
even in case of malformed object code input (right now, pushes become
no-ops when the stack is full, and garbage results if the stack does not
contain enough operands for an op). The refactor would touch some more
places so would be best done in a separate series.

Fixes: CID 407777
Fixes: CID 407778
Signed-off-by: WANG Xuerui <git@xen0n.name>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/kern/loongarch64/dl_helper.c

index e8ec1219fae904b05e577de7268848974e926594..cda1a53c8b35841abd326b4ef205ecb49894f59c 100644 (file)
@@ -46,7 +46,7 @@ static grub_uint64_t
 grub_loongarch64_stack_pop (grub_loongarch64_stack_t stack)
 {
   if (stack->top == -1)
-    return -1;
+    return 0;
   return stack->data[stack->top--];
 }