1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 00:08:50 -05:00

_alpm_parsedate: use strtoll() to parse numeric value

This prepares the function to handle values past year 2038. The return type
is still limited to 32-bits on 32-bit systems; this will be adjusted in a
future patch.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-09-07 09:32:23 -05:00
parent d3d3b861ac
commit 759f435fb9

View File

@ -1109,6 +1109,10 @@ off_t _alpm_strtoofft(const char *line)
time_t _alpm_parsedate(const char *line) time_t _alpm_parsedate(const char *line)
{ {
char *end;
long long result;
errno = 0;
if(isalpha((unsigned char)line[0])) { if(isalpha((unsigned char)line[0])) {
/* initialize to null in case of failure */ /* initialize to null in case of failure */
struct tm tmp_tm; struct tm tmp_tm;
@ -1118,7 +1122,22 @@ time_t _alpm_parsedate(const char *line)
setlocale(LC_TIME, ""); setlocale(LC_TIME, "");
return mktime(&tmp_tm); return mktime(&tmp_tm);
} }
return (time_t)atol(line);
result = strtoll(line, &end, 10);
if (result == 0 && end == line) {
/* line was not a number */
errno = EINVAL;
return (time_t)0;
} else if (errno == ERANGE) {
/* line does not fit in long long */
return (time_t)0;
} else if (*end) {
/* line began with a number but has junk left over at the end */
errno = EINVAL;
return (time_t)0;
}
return (time_t)result;
} }
/** /**