0006-libtasn1-fix-the-potential-buffer-overrun.patch 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. From f629f58b01b3e88052be5e50f51a667181203e05 Mon Sep 17 00:00:00 2001
  2. From: Gary Lin <glin@suse.com>
  3. Date: Mon, 8 Apr 2024 14:57:21 +0800
  4. Subject: [PATCH 06/13] libtasn1: fix the potential buffer overrun
  5. In _asn1_tag_der(), the first while loop for the long form may end up
  6. with a 'k' value with 'ASN1_MAX_TAG_SIZE' and cause the buffer overrun
  7. in the second while loop. This commit tweaks the conditional check to
  8. avoid producing a too large 'k'.
  9. This is a quick fix and may differ from the official upstream fix.
  10. libtasn1 issue: https://gitlab.com/gnutls/libtasn1/-/issues/49
  11. Signed-off-by: Gary Lin <glin@suse.com>
  12. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  13. ---
  14. grub-core/lib/libtasn1-grub/lib/coding.c | 2 +-
  15. 1 file changed, 1 insertion(+), 1 deletion(-)
  16. diff --git a/grub-core/lib/libtasn1-grub/lib/coding.c b/grub-core/lib/libtasn1-grub/lib/coding.c
  17. index 5d03bca9d..0458829a5 100644
  18. --- a/grub-core/lib/libtasn1-grub/lib/coding.c
  19. +++ b/grub-core/lib/libtasn1-grub/lib/coding.c
  20. @@ -143,7 +143,7 @@ _asn1_tag_der (unsigned char class, unsigned int tag_value,
  21. temp[k++] = tag_value & 0x7F;
  22. tag_value >>= 7;
  23. - if (k > ASN1_MAX_TAG_SIZE - 1)
  24. + if (k >= ASN1_MAX_TAG_SIZE - 1)
  25. break; /* will not encode larger tags */
  26. }
  27. *ans_len = k + 1;
  28. --
  29. 2.43.0