From: Christos Zoulas Date: Mon, 14 Mar 2005 16:56:24 +0000 (+0000) Subject: check gmtime and localtime() for NULL. Apparently windows returns NULL X-Git-Tag: FILE5_05~824 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=82bd3a84bf83e711bd86a828dcb7b94422b4b1d8;p=file check gmtime and localtime() for NULL. Apparently windows returns NULL for time 0x80000000 (or with the high bit set). --- diff --git a/src/file.h b/src/file.h index e9e8d809..6ef5c22c 100644 --- a/src/file.h +++ b/src/file.h @@ -27,7 +27,7 @@ */ /* * file.h - definitions for file(1) program - * @(#)$Id: file.h,v 1.66 2005/03/06 05:58:22 christos Exp $ + * @(#)$Id: file.h,v 1.67 2005/03/14 16:56:24 christos Exp $ */ #ifndef __file_h__ @@ -245,7 +245,7 @@ struct magic_set { }; struct stat; -protected char *file_fmttime(uint32_t, int); +protected const char *file_fmttime(uint32_t, int); protected int file_buffer(struct magic_set *, int, const void *, size_t); protected int file_fsmagic(struct magic_set *, const char *, struct stat *); protected int file_pipe2file(struct magic_set *, int, const void *, size_t); diff --git a/src/print.c b/src/print.c index 81eb7895..a6ed790f 100644 --- a/src/print.c +++ b/src/print.c @@ -41,7 +41,7 @@ #include #ifndef lint -FILE_RCSID("@(#)$Id: print.c,v 1.46 2004/11/13 08:11:39 christos Exp $") +FILE_RCSID("@(#)$Id: print.c,v 1.47 2005/03/14 16:56:25 christos Exp $") #endif /* lint */ #define SZOF(a) (sizeof(a) / sizeof(a[0])) @@ -152,7 +152,7 @@ file_magwarn(struct magic_set *ms, const char *f, ...) fputc('\n', stderr); } -protected char * +protected const char * file_fmttime(uint32_t v, int local) { char *pp, *rt; @@ -171,6 +171,8 @@ file_fmttime(uint32_t v, int local) struct tm *tm1; (void)time(&now); tm1 = localtime(&now); + if (tm1 == NULL) + return "*Invalid time*"; daylight = tm1->tm_isdst; } #endif /* HAVE_TM_ISDST */ @@ -178,6 +180,8 @@ file_fmttime(uint32_t v, int local) if (daylight) t += 3600; tm = gmtime(&t); + if (tm == NULL) + return "*Invalid time*"; pp = asctime(tm); }