aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/nabstime.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-05-29 19:16:57 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-05-29 19:16:57 +0000
commit22a517a40c29ec421db8ebd8b1eb17e50b76b406 (patch)
tree10b00ec5ab4eaa84efe85e0072711b80d0414b1a /src/backend/utils/adt/nabstime.c
parentf089c36419adcfc23b3a83560dc67633b1e7b939 (diff)
downloadpostgresql-22a517a40c29ec421db8ebd8b1eb17e50b76b406.tar.gz
postgresql-22a517a40c29ec421db8ebd8b1eb17e50b76b406.zip
Repair problems with overrun of timezone name length. Increase MAXTZLEN
to 10, and be consistent about whether it counts the trailing null (it does not). Also increase MAXDATELEN to be sure no buffer overflows are caused by the longer MAXTZLEN.
Diffstat (limited to 'src/backend/utils/adt/nabstime.c')
-rw-r--r--src/backend/utils/adt/nabstime.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c
index ef18ad02793..a4bb549f1fc 100644
--- a/src/backend/utils/adt/nabstime.c
+++ b/src/backend/utils/adt/nabstime.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.67 2000/04/12 17:15:50 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.68 2000/05/29 19:16:57 tgl Exp $
*
* NOTES
*
@@ -253,12 +253,9 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
* Copy no more than MAXTZLEN bytes of timezone to tzn, in case it
* contains an error message, which doesn't fit in the buffer
*/
- strncpy(tzn, tm->tm_zone, MAXTZLEN);
+ StrNCpy(tzn, tm->tm_zone, MAXTZLEN+1);
if (strlen(tm->tm_zone) > MAXTZLEN)
- {
- tzn[MAXTZLEN] = '\0';
elog(NOTICE, "Invalid timezone \'%s\'", tm->tm_zone);
- }
}
#elif defined(HAVE_INT_TIMEZONE)
if (tzp != NULL)
@@ -274,12 +271,9 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
* Copy no more than MAXTZLEN bytes of timezone to tzn, in case it
* contains an error message, which doesn't fit in the buffer
*/
- strncpy(tzn, tzname[tm->tm_isdst], MAXTZLEN);
+ StrNCpy(tzn, tzname[tm->tm_isdst], MAXTZLEN+1);
if (strlen(tzname[tm->tm_isdst]) > MAXTZLEN)
- {
- tzn[MAXTZLEN] = '\0';
elog(NOTICE, "Invalid timezone \'%s\'", tzname[tm->tm_isdst]);
- }
}
#else
#error POSIX time support is broken
@@ -293,7 +287,10 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
* 97/03/18
*/
if (tzn != NULL)
+ {
strftime(tzn, MAXTZLEN, "%Z", localtime(&now));
+ tzn[MAXTZLEN] = '\0'; /* let's just be sure it's null-terminated */
+ }
#endif
return;