From: Peter Rosin Date: Wed, 8 Oct 2003 07:42:13 +0000 (+0200) Subject: Check return value of localtime call to prevent NULL dereference. X-Git-Tag: NTP_4_2_0~6^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c5b8a3ebaf4c064b0aae585b7ce415d54ef95bde;p=thirdparty%2Fntp.git Check return value of localtime call to prevent NULL dereference. bk: 3f83bfd5JP5eg98VVquzNxjVikCSWQ --- diff --git a/libntp/humandate.c b/libntp/humandate.c index 7995633be4..52f5af1661 100644 --- a/libntp/humandate.c +++ b/libntp/humandate.c @@ -24,11 +24,14 @@ humandate( struct tm *tm; time_t sec; - LIB_GETBUF(bp); - sec = ntptime - JAN_1970; tm = localtime(&sec); + if (!tm) + return "--- --- -- ---- --:--:--"; + + LIB_GETBUF(bp); + (void) sprintf(bp, "%s, %s %2d %4d %2d:%02d:%02d", days[tm->tm_wday], months[tm->tm_mon], tm->tm_mday, 1900+tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec); @@ -47,6 +50,9 @@ humanlogtime(void) time_t cursec = time((time_t *) 0); struct tm *tm = localtime(&cursec); + if (!tm) + return "-- --- --:--:--"; + LIB_GETBUF(bp); (void) sprintf(bp, "%2d %s %02d:%02d:%02d",