From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Sun, 7 May 2017 16:33:12 +0000 (-0400)
Subject: Guard against null t->tm_zone in strftime.c.
X-Git-Tag: REL_10_BETA1~83
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a54d5875fe0bc19d05236b85e1e1bf0af9fa2902;p=postgresql

Guard against null t->tm_zone in strftime.c.

The upstream IANA code does not guard against null TM_ZONE pointers in this
function, but in our code there is such a check in the other pre-existing
use of t->tm_zone.  We do have some places that set pg_tm.tm_zone to NULL.
I'm not entirely sure it's possible to reach strftime with such a value,
but I'm not sure it isn't either, so be safe.

Per Coverity complaint.
---

diff --git a/src/timezone/strftime.c b/src/timezone/strftime.c
index d9a18d49a8..3f6ba395c6 100644
--- a/src/timezone/strftime.c
+++ b/src/timezone/strftime.c
@@ -458,7 +458,8 @@ _fmt(const char *format, const struct pg_tm * t, char *pt, const char *ptlim,
 						negative = diff < 0;
 						if (diff == 0)
 						{
-							negative = t->tm_zone[0] == '-';
+							if (t->tm_zone != NULL)
+								negative = t->tm_zone[0] == '-';
 						}
 						if (negative)
 						{