dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0373-libgcrypt-mpi-Fix-possible-unintended-sign-extension.patch

b1bcb2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b1bcb2
From: Darren Kenny <darren.kenny@oracle.com>
b1bcb2
Date: Tue, 3 Nov 2020 16:43:37 +0000
b1bcb2
Subject: [PATCH] libgcrypt/mpi: Fix possible unintended sign extension
b1bcb2
b1bcb2
The array of unsigned char gets promoted to a signed 32-bit int before
b1bcb2
it is finally promoted to a size_t. There is the possibility that this
b1bcb2
may result in the signed-bit being set for the intermediate signed
b1bcb2
32-bit int. We should ensure that the promotion is to the correct type
b1bcb2
before we bitwise-OR the values.
b1bcb2
b1bcb2
Fixes: CID 96697
b1bcb2
b1bcb2
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
b1bcb2
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
b1bcb2
---
b1bcb2
 grub-core/lib/libgcrypt/mpi/mpicoder.c | 2 +-
b1bcb2
 1 file changed, 1 insertion(+), 1 deletion(-)
b1bcb2
b1bcb2
diff --git a/grub-core/lib/libgcrypt/mpi/mpicoder.c b/grub-core/lib/libgcrypt/mpi/mpicoder.c
b1bcb2
index a3435ed142a..7ecad27b23a 100644
b1bcb2
--- a/grub-core/lib/libgcrypt/mpi/mpicoder.c
b1bcb2
+++ b/grub-core/lib/libgcrypt/mpi/mpicoder.c
b1bcb2
@@ -458,7 +458,7 @@ gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
b1bcb2
       if (len && len < 4)
b1bcb2
         return gcry_error (GPG_ERR_TOO_SHORT);
b1bcb2
 
b1bcb2
-      n = (s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
b1bcb2
+      n = ((size_t)s[0] << 24 | (size_t)s[1] << 16 | (size_t)s[2] << 8 | (size_t)s[3]);
b1bcb2
       s += 4;
b1bcb2
       if (len)
b1bcb2
         len -= 4;