x509asn1: clean up GTime2str
Co-authored-by: Stefan Eissing Reported-by: Dov Murik Closes #14307
This commit is contained in:
parent
abdf612221
commit
3c914bc680
@ -494,7 +494,7 @@ static CURLcode GTime2str(struct dynbuf *store,
|
|||||||
/* Convert an ASN.1 Generalized time to a printable string.
|
/* Convert an ASN.1 Generalized time to a printable string.
|
||||||
Return the dynamically allocated string, or NULL if an error occurs. */
|
Return the dynamically allocated string, or NULL if an error occurs. */
|
||||||
|
|
||||||
for(fracp = beg; fracp < end && *fracp >= '0' && *fracp <= '9'; fracp++)
|
for(fracp = beg; fracp < end && ISDIGIT(*fracp); fracp++)
|
||||||
;
|
;
|
||||||
|
|
||||||
/* Get seconds digits. */
|
/* Get seconds digits. */
|
||||||
@ -513,17 +513,22 @@ static CURLcode GTime2str(struct dynbuf *store,
|
|||||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scan for timezone, measure fractional seconds. */
|
/* timezone follows optional fractional seconds. */
|
||||||
tzp = fracp;
|
tzp = fracp;
|
||||||
fracl = 0;
|
fracl = 0; /* no fractional seconds detected so far */
|
||||||
if(fracp < end && (*fracp == '.' || *fracp == ',')) {
|
if(fracp < end && (*fracp == '.' || *fracp == ',')) {
|
||||||
fracp++;
|
/* Have fractional seconds, e.g. "[.,]\d+". How many? */
|
||||||
do
|
tzp = fracp++; /* should be a digit char or BAD ARGUMENT */
|
||||||
|
while(tzp < end && ISDIGIT(*tzp))
|
||||||
tzp++;
|
tzp++;
|
||||||
while(tzp < end && *tzp >= '0' && *tzp <= '9');
|
if(tzp == fracp) /* never looped, no digit after [.,] */
|
||||||
/* Strip leading zeroes in fractional seconds. */
|
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||||
for(fracl = tzp - fracp - 1; fracl && fracp[fracl - 1] == '0'; fracl--)
|
fracl = tzp - fracp - 1; /* number of fractional sec digits */
|
||||||
;
|
DEBUGASSERT(fracl > 0);
|
||||||
|
/* Strip trailing zeroes in fractional seconds.
|
||||||
|
* May reduce fracl to 0 if only '0's are present. */
|
||||||
|
while(fracl && fracp[fracl - 1] == '0')
|
||||||
|
fracl--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process timezone. */
|
/* Process timezone. */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user