Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit22a517a

Browse files
committed
Repair problems with overrun of timezone name length. Increase MAXTZLEN
to 10, and be consistent about whether it counts the trailing null (itdoes not). Also increase MAXDATELEN to be sure no buffer overflows arecaused by the longer MAXTZLEN.
1 parentf089c36 commit22a517a

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

‎src/backend/utils/adt/datetime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.47 2000/04/14 15:22:10 thomas Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.48 2000/05/29 19:16:57 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2153,7 +2153,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
21532153
if ((*tzn!=NULL)&& (tm->tm_isdst >=0))
21542154
{
21552155
strcpy((str+27)," ");
2156-
strncpy((str+28),*tzn,MAXTZLEN);
2156+
StrNCpy((str+28),*tzn,MAXTZLEN+1);
21572157
}
21582158
}
21592159
else
@@ -2162,7 +2162,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
21622162
if ((*tzn!=NULL)&& (tm->tm_isdst >=0))
21632163
{
21642164
strcpy((str+24)," ");
2165-
strncpy((str+25),*tzn,MAXTZLEN);
2165+
StrNCpy((str+25),*tzn,MAXTZLEN+1);
21662166
}
21672167
}
21682168

‎src/backend/utils/adt/nabstime.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.67 2000/04/12 17:15:50 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.68 2000/05/29 19:16:57 tgl Exp $
1313
*
1414
* NOTES
1515
*
@@ -253,12 +253,9 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
253253
* Copy no more than MAXTZLEN bytes of timezone to tzn, in case it
254254
* contains an error message, which doesn't fit in the buffer
255255
*/
256-
strncpy(tzn,tm->tm_zone,MAXTZLEN);
256+
StrNCpy(tzn,tm->tm_zone,MAXTZLEN+1);
257257
if (strlen(tm->tm_zone)>MAXTZLEN)
258-
{
259-
tzn[MAXTZLEN]='\0';
260258
elog(NOTICE,"Invalid timezone \'%s\'",tm->tm_zone);
261-
}
262259
}
263260
#elif defined(HAVE_INT_TIMEZONE)
264261
if (tzp!=NULL)
@@ -274,12 +271,9 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
274271
* Copy no more than MAXTZLEN bytes of timezone to tzn, in case it
275272
* contains an error message, which doesn't fit in the buffer
276273
*/
277-
strncpy(tzn,tzname[tm->tm_isdst],MAXTZLEN);
274+
StrNCpy(tzn,tzname[tm->tm_isdst],MAXTZLEN+1);
278275
if (strlen(tzname[tm->tm_isdst])>MAXTZLEN)
279-
{
280-
tzn[MAXTZLEN]='\0';
281276
elog(NOTICE,"Invalid timezone \'%s\'",tzname[tm->tm_isdst]);
282-
}
283277
}
284278
#else
285279
#error POSIX time support is broken
@@ -293,7 +287,10 @@ abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
293287
* 97/03/18
294288
*/
295289
if (tzn!=NULL)
290+
{
296291
strftime(tzn,MAXTZLEN,"%Z",localtime(&now));
292+
tzn[MAXTZLEN]='\0';/* let's just be sure it's null-terminated */
293+
}
297294
#endif
298295

299296
return;

‎src/include/miscadmin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: miscadmin.h,v 1.55 2000/04/12 17:16:24 momjian Exp $
15+
* $Id: miscadmin.h,v 1.56 2000/05/29 19:16:55 tgl Exp $
1616
*
1717
* NOTES
1818
* some of the information in this file will be moved to
@@ -85,7 +85,7 @@ extern intDebugLvl;
8585
* CTZName is the timezone label.
8686
*/
8787

88-
#defineMAXTZLEN7
88+
#defineMAXTZLEN10/* max TZ name len, not counting tr. null */
8989

9090
#defineUSE_POSTGRES_DATES0
9191
#defineUSE_ISO_DATES1

‎src/include/utils/datetime.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $Id: datetime.h,v 1.13 2000/04/14 15:22:22 thomas Exp $
12+
* $Id: datetime.h,v 1.14 2000/05/29 19:16:56 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -163,8 +163,8 @@
163163
#defineDTK_DATE_M(DTK_M(YEAR) | DTK_M(MONTH) | DTK_M(DAY))
164164
#defineDTK_TIME_M(DTK_M(HOUR) | DTK_M(MINUTE) | DTK_M(SECOND))
165165

166-
#defineMAXDATELEN47/* maximum possible length of an input
167-
* date string */
166+
#defineMAXDATELEN51/* maximum possible length of an input
167+
* date string(not counting tr. null)*/
168168
#defineMAXDATEFIELDS25/* maximum possible number of fields in a
169169
* date string */
170170
#defineTOKMAXLEN10/* only this many chars are stored in

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp