diff options
author | Dan McGee <dan@archlinux.org> | 2011-09-07 09:32:23 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-10-12 14:01:25 -0500 |
commit | 759f435fb91a3abf64a422b53f939a774332cd8a (patch) | |
tree | fd9cf360304cc414a55fd50b66883aecf8f475de /lib | |
parent | d3d3b861ac2c4ce63c306e00395945bfa3c1b6c6 (diff) | |
download | pacman-759f435fb91a3abf64a422b53f939a774332cd8a.tar.xz |
_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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/util.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index beefa936..243978cd 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -1109,6 +1109,10 @@ off_t _alpm_strtoofft(const char *line) time_t _alpm_parsedate(const char *line) { + char *end; + long long result; + errno = 0; + if(isalpha((unsigned char)line[0])) { /* initialize to null in case of failure */ struct tm tmp_tm; @@ -1118,7 +1122,22 @@ time_t _alpm_parsedate(const char *line) setlocale(LC_TIME, ""); 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; } /** |