diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-01-10 20:16:25 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-01-10 20:16:25 +0000 |
commit | 2946ccf35f3a2ba1f3eb78bdc24433ad2d472192 (patch) | |
tree | b8616db0f172af73c0ab1b10e7a4a2b57a727149 /src | |
parent | 95f88ddf4940ec2b1adf3e251f54914fc668c802 (diff) | |
download | postgresql-2946ccf35f3a2ba1f3eb78bdc24433ad2d472192.tar.gz postgresql-2946ccf35f3a2ba1f3eb78bdc24433ad2d472192.zip |
Fix pg_tzset() to ensure that 'lclmem' (the static variable holding
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/timezone/localtime.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c index 8e64f065b45..64ed06185f0 100644 --- a/src/timezone/localtime.c +++ b/src/timezone/localtime.c @@ -3,7 +3,7 @@ * 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). * * IDENTIFICATION - * $PostgreSQL: pgsql/src/timezone/localtime.c,v 1.9 2004/11/01 21:34:44 tgl Exp $ + * $PostgreSQL: pgsql/src/timezone/localtime.c,v 1.9.4.1 2006/01/10 20:16:25 tgl Exp $ */ /* @@ -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; |