|
| 1 | +diff --git a/lib/vtls/x509asn1.c b/lib/vtls/x509asn1.c |
| 2 | +index 39e4fb33b..7e2e3d724 100644 |
| 3 | +--- a/lib/vtls/x509asn1.c |
| 4 | ++++ b/lib/vtls/x509asn1.c |
| 5 | +@@ -566,28 +566,40 @@ static const char *GTime2str(const char *beg, const char *end) |
| 6 | + tzp = fracp; |
| 7 | + fracl = 0; |
| 8 | + if(fracp < end && (*fracp == '.' || *fracp == ',')) { |
| 9 | +- fracp++; |
| 10 | +- do |
| 11 | ++ /* Have fractional seconds, e.g. "[.,]\d+". How many? */ |
| 12 | ++ fracp++; /* should be a digit char or BAD ARGUMENT */ |
| 13 | ++ tzp = fracp; |
| 14 | ++ while(tzp < end && ISDIGIT(*tzp)) |
| 15 | + tzp++; |
| 16 | +- while(tzp < end && *tzp >= '0' && *tzp <= '9'); |
| 17 | +- /* Strip leading zeroes in fractional seconds. */ |
| 18 | +- for(fracl = tzp - fracp - 1; fracl && fracp[fracl - 1] == '0'; fracl--) |
| 19 | +- ; |
| 20 | ++ if(tzp == fracp) /* never looped, no digit after [.,] */ |
| 21 | ++ return CURLE_BAD_FUNCTION_ARGUMENT; |
| 22 | ++ fracl = tzp - fracp; /* number of fractional sec digits */ |
| 23 | ++ DEBUGASSERT(fracl > 0); |
| 24 | ++ /* Strip trailing zeroes in fractional seconds. |
| 25 | ++ * May reduce fracl to 0 if only '0's are present. */ |
| 26 | ++ while(fracl && fracp[fracl - 1] == '0') |
| 27 | ++ fracl--; |
| 28 | + } |
| 29 | + |
| 30 | + /* Process timezone. */ |
| 31 | +- if(tzp >= end) |
| 32 | +- ; /* Nothing to do. */ |
| 33 | ++ if(tzp >= end) { |
| 34 | ++ sep = " "; |
| 35 | ++ tzp = "GMT"; |
| 36 | ++ tzl = 3; |
| 37 | ++ } |
| 38 | ++ else if((*tzp == '+') || (*tzp == '-')) { |
| 39 | ++ sep = " UTC"; |
| 40 | ++ tzl = end - tzp; |
| 41 | ++ } /* Nothing to do. */ |
| 42 | + else if(*tzp == 'Z') { |
| 43 | + tzp = " GMT"; |
| 44 | + end = tzp + 4; |
| 45 | + } |
| 46 | + else { |
| 47 | + sep = " "; |
| 48 | +- tzp++; |
| 49 | ++ tzl = end - tzp; |
| 50 | + } |
| 51 | + |
| 52 | +- tzl = end - tzp; |
| 53 | + return curl_maprintf("%.4s-%.2s-%.2s %.2s:%.2s:%c%c%s%.*s%s%.*s", |
| 54 | + beg, beg + 4, beg + 6, |
| 55 | + beg + 8, beg + 10, sec1, sec2, |
| 56 | +@@ -595,6 +607,15 @@ static const char *GTime2str(const char *beg, const char *end) |
| 57 | + sep, (int)tzl, tzp); |
| 58 | + } |
| 59 | + |
| 60 | ++#ifdef UNITTESTS |
| 61 | ++/* used by unit1656.c */ |
| 62 | ++CURLcode Curl_x509_GTime2str(struct dynbuf *store, |
| 63 | ++ const char *beg, const char *end) |
| 64 | ++{ |
| 65 | ++ return GTime2str(store, beg, end); |
| 66 | ++} |
| 67 | ++#endif |
| 68 | ++ |
| 69 | + /* |
| 70 | + * Convert an ASN.1 UTC time to a printable string. |
| 71 | + * Return the dynamically allocated string, or NULL if an error occurs. |
| 72 | +diff --git a/lib/vtls/x509asn1.h b/lib/vtls/x509asn1.h |
| 73 | +index 5496de40e..93925718c 100644 |
| 74 | +--- a/lib/vtls/x509asn1.h |
| 75 | ++++ b/lib/vtls/x509asn1.h |
| 76 | +@@ -76,6 +76,17 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data, int certnum, |
| 77 | + const char *beg, const char *end); |
| 78 | + CURLcode Curl_verifyhost(struct Curl_cfilter *cf, struct Curl_easy *data, |
| 79 | + const char *beg, const char *end); |
| 80 | ++ |
| 81 | ++#ifdef UNITTESTS |
| 82 | ++#if defined(USE_GNUTLS) || defined(USE_SCHANNEL) || defined(USE_SECTRANSP) || \ |
| 83 | ++ defined(USE_MBEDTLS) |
| 84 | ++ |
| 85 | ++/* used by unit1656.c */ |
| 86 | ++CURLcode Curl_x509_GTime2str(struct dynbuf *store, |
| 87 | ++ const char *beg, const char *end); |
| 88 | ++#endif |
| 89 | ++#endif |
| 90 | ++ |
| 91 | + #endif /* USE_GSKIT or USE_NSS or USE_GNUTLS or USE_WOLFSSL or USE_SCHANNEL |
| 92 | + * or USE_SECTRANSP */ |
| 93 | + #endif /* HEADER_CURL_X509ASN1_H */ |
0 commit comments