Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 94f8f63

Browse files
committed
Must guard against NULL return from localtime() when probing pre-1970
dates. Per Magnus Hagander.
1 parent d01af77 commit 94f8f63

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/timezone/pgtz.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.19 2004/07/22 05:28:30 tgl Exp $
9+
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.20 2004/07/30 17:31:24 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -182,6 +182,15 @@ score_timezone(const char *tzname, struct tztry *tt)
182182
if (!pgtm)
183183
return -1; /* probably shouldn't happen */
184184
systm = localtime(&(tt->test_times[i]));
185+
if (!systm)
186+
{
187+
elog(DEBUG4, "TZ \"%s\" scores %d: at %ld %04d-%02d-%02d %02d:%02d:%02d %s, system had no data",
188+
tzname, i, (long) pgtt,
189+
pgtm->tm_year + 1900, pgtm->tm_mon + 1, pgtm->tm_mday,
190+
pgtm->tm_hour, pgtm->tm_min, pgtm->tm_sec,
191+
pgtm->tm_isdst ? "dst" : "std");
192+
return i;
193+
}
185194
if (!compare_tm(systm, pgtm))
186195
{
187196
elog(DEBUG4, "TZ \"%s\" scores %d: at %ld %04d-%02d-%02d %02d:%02d:%02d %s versus %04d-%02d-%02d %02d:%02d:%02d %s",
@@ -302,6 +311,8 @@ identify_system_timezone(void)
302311
for (t = tnow; t <= tnow + T_MONTH * 14; t += T_MONTH)
303312
{
304313
tm = localtime(&t);
314+
if (!tm)
315+
continue;
305316
if (tm->tm_isdst < 0)
306317
continue;
307318
if (tm->tm_isdst == 0 && std_zone_name[0] == '\0')
@@ -491,7 +502,7 @@ tz_acceptable(void)
491502
*/
492503
time2000 = (POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * 86400;
493504
tt = pg_localtime(&time2000);
494-
if (tt->tm_sec != 0)
505+
if (!tt || tt->tm_sec != 0)
495506
return false;
496507

497508
return true;

0 commit comments

Comments
 (0)