|
| 1 | +From e09204d779434ff6ed01532ee8c04c44018b8abe Mon Sep 17 00:00:00 2001 |
| 2 | +From: jykanase < [email protected]> |
| 3 | +Date: Mon, 27 Jan 2025 05:08:31 +0000 |
| 4 | +Subject: [PATCH] CVE-2024-7264 |
| 5 | + |
| 6 | +--- |
| 7 | + Utilities/cmcurl/lib/vtls/x509asn1.c | 51 ++++++++++++++++++++-------- |
| 8 | + Utilities/cmcurl/lib/vtls/x509asn1.h | 11 ++++++ |
| 9 | + 2 files changed, 47 insertions(+), 15 deletions(-) |
| 10 | + |
| 11 | +diff --git a/Utilities/cmcurl/lib/vtls/x509asn1.c b/Utilities/cmcurl/lib/vtls/x509asn1.c |
| 12 | +index ed84032a..b5412c50 100644 |
| 13 | +--- a/Utilities/cmcurl/lib/vtls/x509asn1.c |
| 14 | ++++ b/Utilities/cmcurl/lib/vtls/x509asn1.c |
| 15 | +@@ -491,7 +491,7 @@ static CURLcode GTime2str(struct dynbuf *store, |
| 16 | + /* Convert an ASN.1 Generalized time to a printable string. |
| 17 | + Return the dynamically allocated string, or NULL if an error occurs. */ |
| 18 | + |
| 19 | +- for(fracp = beg; fracp < end && *fracp >= '0' && *fracp <= '9'; fracp++) |
| 20 | ++ for(fracp = beg; fracp < end && ISDIGIT(*fracp); fracp++) |
| 21 | + ; |
| 22 | + |
| 23 | + /* Get seconds digits. */ |
| 24 | +@@ -510,32 +510,44 @@ static CURLcode GTime2str(struct dynbuf *store, |
| 25 | + return CURLE_BAD_FUNCTION_ARGUMENT; |
| 26 | + } |
| 27 | + |
| 28 | +- /* Scan for timezone, measure fractional seconds. */ |
| 29 | ++ /* timezone follows optional fractional seconds. */ |
| 30 | + tzp = fracp; |
| 31 | +- fracl = 0; |
| 32 | ++ fracl = 0; /* no fractional seconds detected so far */ |
| 33 | + if(fracp < end && (*fracp == '.' || *fracp == ',')) { |
| 34 | +- fracp++; |
| 35 | +- do |
| 36 | ++ /* Have fractional seconds, e.g. "[.,]\d+". How many? */ |
| 37 | ++ fracp++; /* should be a digit char or BAD ARGUMENT */ |
| 38 | ++ tzp = fracp; |
| 39 | ++ while(tzp < end && ISDIGIT(*tzp)) |
| 40 | + tzp++; |
| 41 | +- while(tzp < end && *tzp >= '0' && *tzp <= '9'); |
| 42 | +- /* Strip leading zeroes in fractional seconds. */ |
| 43 | +- for(fracl = tzp - fracp - 1; fracl && fracp[fracl - 1] == '0'; fracl--) |
| 44 | +- ; |
| 45 | ++ if(tzp == fracp) /* never looped, no digit after [.,] */ |
| 46 | ++ return CURLE_BAD_FUNCTION_ARGUMENT; |
| 47 | ++ fracl = tzp - fracp; /* number of fractional sec digits */ |
| 48 | ++ DEBUGASSERT(fracl > 0); |
| 49 | ++ /* Strip trailing zeroes in fractional seconds. |
| 50 | ++ * May reduce fracl to 0 if only '0's are present. */ |
| 51 | ++ while(fracl && fracp[fracl - 1] == '0') |
| 52 | ++ fracl--; |
| 53 | + } |
| 54 | + |
| 55 | + /* Process timezone. */ |
| 56 | +- if(tzp >= end) |
| 57 | +- ; /* Nothing to do. */ |
| 58 | ++ if(tzp >= end) { |
| 59 | ++ tzp = ""; |
| 60 | ++ tzl = 0; |
| 61 | ++ } |
| 62 | + else if(*tzp == 'Z') { |
| 63 | +- tzp = " GMT"; |
| 64 | +- end = tzp + 4; |
| 65 | ++ sep = " "; |
| 66 | ++ tzp = "GMT"; |
| 67 | ++ tzl = 3; |
| 68 | ++ } |
| 69 | ++ else if((*tzp == '+') || (*tzp == '-')) { |
| 70 | ++ sep = " UTC"; |
| 71 | ++ tzl = end - tzp; |
| 72 | + } |
| 73 | + else { |
| 74 | + sep = " "; |
| 75 | +- tzp++; |
| 76 | ++ tzl = end - tzp; |
| 77 | + } |
| 78 | + |
| 79 | +- tzl = end - tzp; |
| 80 | + return Curl_dyn_addf(store, |
| 81 | + "%.4s-%.2s-%.2s %.2s:%.2s:%c%c%s%.*s%s%.*s", |
| 82 | + beg, beg + 4, beg + 6, |
| 83 | +@@ -544,6 +556,15 @@ static CURLcode GTime2str(struct dynbuf *store, |
| 84 | + sep, (int)tzl, tzp); |
| 85 | + } |
| 86 | + |
| 87 | ++#ifdef UNITTESTS |
| 88 | ++/* used by unit1656.c */ |
| 89 | ++CURLcode Curl_x509_GTime2str(struct dynbuf *store, |
| 90 | ++ const char *beg, const char *end) |
| 91 | ++{ |
| 92 | ++ return GTime2str(store, beg, end); |
| 93 | ++} |
| 94 | ++#endif |
| 95 | ++ |
| 96 | + /* |
| 97 | + * Convert an ASN.1 UTC time to a printable string. |
| 98 | + * |
| 99 | +diff --git a/Utilities/cmcurl/lib/vtls/x509asn1.h b/Utilities/cmcurl/lib/vtls/x509asn1.h |
| 100 | +index 23a67b82..1d8bbabc 100644 |
| 101 | +--- a/Utilities/cmcurl/lib/vtls/x509asn1.h |
| 102 | ++++ b/Utilities/cmcurl/lib/vtls/x509asn1.h |
| 103 | +@@ -76,5 +76,16 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, int certnum, |
| 104 | + const char *beg, const char *end); |
| 105 | + CURLcode Curl_verifyhost(struct Curl_cfilter *cf, struct Curl_easy *data, |
| 106 | + const char *beg, const char *end); |
| 107 | ++ |
| 108 | ++#ifdef UNITTESTS |
| 109 | ++#if defined(USE_GNUTLS) || defined(USE_SCHANNEL) || defined(USE_SECTRANSP) || \ |
| 110 | ++ defined(USE_MBEDTLS) |
| 111 | ++ |
| 112 | ++/* used by unit1656.c */ |
| 113 | ++CURLcode Curl_x509_GTime2str(struct dynbuf *store, |
| 114 | ++ const char *beg, const char *end); |
| 115 | ++#endif |
| 116 | ++#endif |
| 117 | ++ |
| 118 | + #endif /* USE_GNUTLS or USE_WOLFSSL or USE_SCHANNEL or USE_SECTRANSP */ |
| 119 | + #endif /* HEADER_CURL_X509ASN1_H */ |
| 120 | +-- |
| 121 | +2.45.2 |
| 122 | + |
0 commit comments