nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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