Fix pg_tzset() to ensure that 'lclmem' (the static variable holding
authorTom Lane <[email protected]>
Tue, 10 Jan 2006 20:16:25 +0000 (20:16 +0000)
committerTom Lane <[email protected]>
Tue, 10 Jan 2006 20:16:25 +0000 (20:16 +0000)
the localtime timezone data) is not overwritten until we know the data
is good.  tzload() is capable of failing after having begun modifying
the struct it's pointed at, and in such cases the static data was left
in a corrupt state.  Bug does not exist pre-8.0 (since we didn't have
this code then) nor post-8.0 (since we already changed the code to
tzload into local variables initially).  Per report from Nick Martens.

src/timezone/localtime.c

index dd8bdb8a3777a5b1e02e70883160e6d2407b0750..92335ddcc9e5043a940ed6a76e359860b8d1a558 100644 (file)
@@ -842,21 +842,24 @@ gmtload(struct state * sp)
 bool
 pg_tzset(const char *name)
 {
+       struct state tmpmem;
+
        if (lcl_is_set && strcmp(lcl_TZname, name) == 0)
                return true;                    /* no change */
 
        if (strlen(name) >= sizeof(lcl_TZname))
                return false;                   /* not gonna fit */
 
-       if (tzload(name, lclptr) != 0)
+       if (tzload(name, &tmpmem) != 0)
        {
-               if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
+               if (name[0] == ':' || tzparse(name, &tmpmem, FALSE) != 0)
                {
                        /* Unknown timezone. Fail our call instead of loading GMT! */
                        return false;
                }
        }
 
+       memcpy(lclptr, &tmpmem, sizeof(struct state));
        strcpy(lcl_TZname, name);
        lcl_is_set = true;