Fix crash when reading 'timezone = unknown' from postgresql.conf during
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 8 Aug 2005 23:39:14 +0000 (23:39 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 8 Aug 2005 23:39:14 +0000 (23:39 +0000)
SIGHUP; it's not OK for an assign_hook to return a non-malloc'd string.
Problem was introduced during timezone library rewrite.

src/backend/commands/variable.c

index a73b39f98c5d10a6dc765bddc4bcb720e3844406..5992aca2a304be848125236613e57e69203f67ed 100644 (file)
@@ -284,7 +284,11 @@ assign_timezone(const char *value, bool doit, GucSource source)
                if (doit)
                {
                        /* Here we change from SQL to Unix sign convention */
+#ifdef HAVE_INT64_TIMESTAMP
+                       CTimeZone = -(interval->time / INT64CONST(1000000));
+#else
                        CTimeZone = -interval->time;
+#endif
 
                        HasCTZSet = true;
                }
@@ -321,10 +325,13 @@ assign_timezone(const char *value, bool doit, GucSource source)
                         * pg_timezone_initialize() will eventually select a default
                         * value from the environment.
                         */
-                       const char *curzone = pg_get_current_timezone();
+                       if (doit)
+                       {
+                               const char *curzone = pg_get_current_timezone();
 
-                       if (curzone)
-                               value = curzone;
+                               if (curzone)
+                                       value = curzone;
+                       }
                }
                else
                {
@@ -452,8 +459,12 @@ show_timezone(void)
        {
                Interval interval;
 
-               interval.       month = 0;
-               interval.       time = -CTimeZone;
+               interval.month = 0;
+#ifdef HAVE_INT64_TIMESTAMP
+               interval.time = -(CTimeZone * INT64CONST(1000000));
+#else
+               interval.time = -CTimeZone;
+#endif
 
                tzn = DatumGetCString(DirectFunctionCall1(interval_out,
                                                                                  IntervalPGetDatum(&interval)));