0073-libgcrypt-mpi-Fix-possible-unintended-sign-extension.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. From e8814c811132a70f9b55418f7567378a34ad3883 Mon Sep 17 00:00:00 2001
  2. From: Darren Kenny <darren.kenny@oracle.com>
  3. Date: Tue, 3 Nov 2020 16:43:37 +0000
  4. Subject: [PATCH] libgcrypt/mpi: Fix possible unintended sign extension
  5. The array of unsigned char gets promoted to a signed 32-bit int before
  6. it is finally promoted to a size_t. There is the possibility that this
  7. may result in the signed-bit being set for the intermediate signed
  8. 32-bit int. We should ensure that the promotion is to the correct type
  9. before we bitwise-OR the values.
  10. Fixes: CID 96697
  11. Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
  12. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  13. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  14. ---
  15. grub-core/lib/libgcrypt-grub/mpi/mpicoder.c | 2 +-
  16. grub-core/lib/libgcrypt/mpi/mpicoder.c | 2 +-
  17. 2 files changed, 2 insertions(+), 2 deletions(-)
  18. diff --git a/grub-core/lib/libgcrypt-grub/mpi/mpicoder.c b/grub-core/lib/libgcrypt-grub/mpi/mpicoder.c
  19. index 3d55dfc..faf1cd6 100644
  20. --- a/grub-core/lib/libgcrypt-grub/mpi/mpicoder.c
  21. +++ b/grub-core/lib/libgcrypt-grub/mpi/mpicoder.c
  22. @@ -460,7 +460,7 @@ gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
  23. if (len && len < 4)
  24. return gcry_error (GPG_ERR_TOO_SHORT);
  25. - n = (s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
  26. + n = ((size_t)s[0] << 24 | (size_t)s[1] << 16 | (size_t)s[2] << 8 | (size_t)s[3]);
  27. s += 4;
  28. if (len)
  29. len -= 4;
  30. diff --git a/grub-core/lib/libgcrypt/mpi/mpicoder.c b/grub-core/lib/libgcrypt/mpi/mpicoder.c
  31. index a3435ed..7ecad27 100644
  32. --- a/grub-core/lib/libgcrypt/mpi/mpicoder.c
  33. +++ b/grub-core/lib/libgcrypt/mpi/mpicoder.c
  34. @@ -458,7 +458,7 @@ gcry_mpi_scan (struct gcry_mpi **ret_mpi, enum gcry_mpi_format format,
  35. if (len && len < 4)
  36. return gcry_error (GPG_ERR_TOO_SHORT);
  37. - n = (s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
  38. + n = ((size_t)s[0] << 24 | (size_t)s[1] << 16 | (size_t)s[2] << 8 | (size_t)s[3]);
  39. s += 4;
  40. if (len)
  41. len -= 4;
  42. --
  43. 2.14.2