0001-Check-domain-name-location-index-hasn-t-exceed-maxim.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From 52f28bd5149360f8e3bf8ca13d3fb9a77283df7c Mon Sep 17 00:00:00 2001
  2. From: Sean Parkinson <sean@wolfssl.com>
  3. Date: Wed, 6 Nov 2019 08:28:09 +1000
  4. Subject: [PATCH] Check domain name location index hasn't exceed maximum before
  5. setting
  6. [CVE-2019–18840]
  7. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  8. ---
  9. wolfcrypt/src/asn.c | 30 ++++++++++++++++++++----------
  10. 1 file changed, 20 insertions(+), 10 deletions(-)
  11. diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c
  12. index 637f4c355..d3793b7b3 100644
  13. --- a/wolfcrypt/src/asn.c
  14. +++ b/wolfcrypt/src/asn.c
  15. @@ -5117,8 +5117,10 @@ static int GetName(DecodedCert* cert, int nameType)
  16. XMEMCPY(&full[idx], &cert->source[cert->srcIdx], strLen);
  17. idx += strLen;
  18. #if defined(OPENSSL_EXTRA)
  19. - /* store order that DN was parsed */
  20. - dName->loc[count++] = id;
  21. + if (count < DOMAIN_COMPONENT_MAX) {
  22. + /* store order that DN was parsed */
  23. + dName->loc[count++] = id;
  24. + }
  25. #endif
  26. }
  27. @@ -5191,8 +5193,10 @@ static int GetName(DecodedCert* cert, int nameType)
  28. XMEMCPY(&full[idx], &cert->source[cert->srcIdx], strLen);
  29. idx += strLen;
  30. #if defined(OPENSSL_EXTRA)
  31. - /* store order that DN was parsed */
  32. - dName->loc[count++] = id;
  33. + if (count < DOMAIN_COMPONENT_MAX) {
  34. + /* store order that DN was parsed */
  35. + dName->loc[count++] = id;
  36. + }
  37. #endif
  38. }
  39. @@ -5276,8 +5280,10 @@ static int GetName(DecodedCert* cert, int nameType)
  40. XMEMCPY(&full[idx], &cert->source[cert->srcIdx], adv);
  41. idx += adv;
  42. #if defined(OPENSSL_EXTRA)
  43. - /* store order that DN was parsed */
  44. - dName->loc[count++] = ASN_EMAIL_NAME;
  45. + if (count < DOMAIN_COMPONENT_MAX) {
  46. + /* store order that DN was parsed */
  47. + dName->loc[count++] = ASN_EMAIL_NAME;
  48. + }
  49. #endif
  50. }
  51. }
  52. @@ -5298,8 +5304,10 @@ static int GetName(DecodedCert* cert, int nameType)
  53. dName->uidLen = adv;
  54. #ifdef OPENSSL_EXTRA
  55. - /* store order that DN was parsed */
  56. - dName->loc[count++] = ASN_USER_ID;
  57. + if (count < DOMAIN_COMPONENT_MAX) {
  58. + /* store order that DN was parsed */
  59. + dName->loc[count++] = ASN_USER_ID;
  60. + }
  61. #endif
  62. #endif /* OPENSSL_EXTRA */
  63. break;
  64. @@ -5315,8 +5323,10 @@ static int GetName(DecodedCert* cert, int nameType)
  65. dcnum++;
  66. #ifdef OPENSSL_EXTRA
  67. - /* store order that DN was parsed */
  68. - dName->loc[count++] = ASN_DOMAIN_COMPONENT;
  69. + if (count < DOMAIN_COMPONENT_MAX) {
  70. + /* store order that DN was parsed */
  71. + dName->loc[count++] = ASN_DOMAIN_COMPONENT;
  72. + }
  73. #endif
  74. #endif /* OPENSSL_EXTRA */
  75. break;
  76. --
  77. 2.20.1