From 759f435fb91a3abf64a422b53f939a774332cd8a Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 7 Sep 2011 09:32:23 -0500 Subject: _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 --- lib/libalpm/util.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') 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; } /** -- cgit v1.2.3-24-g4f1b