From: Michihiro NAKAJIMA Date: Thu, 19 Jan 2012 07:31:31 +0000 (-0500) Subject: If the format of times in ISO images is invalid, reset the time to 0. X-Git-Tag: v3.0.4~2^2~171 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8007f5ddfa4b9604402e22c47e17b331ce153ab7;p=thirdparty%2Flibarchive.git If the format of times in ISO images is invalid, reset the time to 0. SVN-Revision: 4180 --- diff --git a/libarchive/archive_read_support_format_iso9660.c b/libarchive/archive_read_support_format_iso9660.c index 0f0c3d66f..942dfe253 100644 --- a/libarchive/archive_read_support_format_iso9660.c +++ b/libarchive/archive_read_support_format_iso9660.c @@ -3085,6 +3085,8 @@ isodate7(const unsigned char *v) { struct tm tm; int offset; + time_t t; + memset(&tm, 0, sizeof(tm)); tm.tm_year = v[0]; tm.tm_mon = v[1] - 1; @@ -3098,7 +3100,10 @@ isodate7(const unsigned char *v) tm.tm_hour -= offset / 4; tm.tm_min -= (offset % 4) * 15; } - return (time_from_tm(&tm)); + t = time_from_tm(&tm); + if (t == (time_t)-1) + return ((time_t)0); + return (t); } static time_t @@ -3106,6 +3111,8 @@ isodate17(const unsigned char *v) { struct tm tm; int offset; + time_t t; + memset(&tm, 0, sizeof(tm)); tm.tm_year = (v[0] - '0') * 1000 + (v[1] - '0') * 100 + (v[2] - '0') * 10 + (v[3] - '0') @@ -3121,7 +3128,10 @@ isodate17(const unsigned char *v) tm.tm_hour -= offset / 4; tm.tm_min -= (offset % 4) * 15; } - return (time_from_tm(&tm)); + t = time_from_tm(&tm); + if (t == (time_t)-1) + return ((time_t)0); + return (t); } static time_t @@ -3135,7 +3145,8 @@ time_from_tm(struct tm *t) #else /* Else use direct calculation using POSIX assumptions. */ /* First, fix up tm_yday based on the year/month/day. */ - mktime(t); + if (mktime(t) == (time_t)-1) + return ((time_t)-1); /* Then we can compute timegm() from first principles. */ return (t->tm_sec + t->tm_min * 60 + t->tm_hour * 3600 + t->tm_yday * 86400 + (t->tm_year - 70) * 31536000