nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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