*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.57 2001/12/09 04:37:50 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.57.2.1 2002/08/22 05:27:41 momjian Exp $
*
*-------------------------------------------------------------------------
*/
show_datestyle(void)
{
char buf[64];
+ char *dstyle;
- strcpy(buf, "DateStyle is ");
switch (DateStyle)
{
case USE_ISO_DATES:
- strcat(buf, "ISO");
+ dstyle = "ISO";
break;
case USE_SQL_DATES:
- strcat(buf, "SQL");
+ dstyle = "SQL";
break;
case USE_GERMAN_DATES:
- strcat(buf, "German");
+ dstyle = "German";
break;
default:
- strcat(buf, "Postgres");
+ dstyle = "Postgres";
break;
- };
- strcat(buf, " with ");
- strcat(buf, ((EuroDates) ? "European" : "US (NonEuropean)"));
- strcat(buf, " conventions");
+ }
+
+ snprintf(buf, sizeof(buf), "DateStyle is %s with %s conventions",
+ dstyle, EuroDates ? "European" : "US (NonEuropean");
elog(NOTICE, buf, NULL);
{
/* found something? then save it for later */
if ((defaultTZ = getenv("TZ")) != NULL)
- strcpy(TZvalue, defaultTZ);
+ strncpy(TZvalue, defaultTZ, sizeof(TZvalue));
/* found nothing so mark with an invalid pointer */
else
defaultTZ = (char *) -1;
}
- strcpy(tzbuf, "TZ=");
- strcat(tzbuf, tok);
+ snprintf(tzbuf, sizeof(tzbuf), "TZ=%s", tok);
if (putenv(tzbuf) != 0)
elog(ERROR, "Unable to set TZ environment variable to %s", tok);
/* time zone was set and original explicit time zone available? */
else if (defaultTZ != (char *) -1)
{
- strcpy(tzbuf, "TZ=");
- strcat(tzbuf, TZvalue);
+ snprintf(tzbuf, sizeof(tzbuf), "TZ=%s", TZvalue);
if (putenv(tzbuf) != 0)
elog(ERROR, "Unable to set TZ environment variable to %s", TZvalue);
tzset();
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.64.2.1 2002/03/15 23:37:48 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.64.2.2 2002/08/22 05:27:41 momjian Exp $
*
*-------------------------------------------------------------------------
*/
int ftype[MAXDATEFIELDS];
char lowstr[MAXDATELEN + 1];
+ if (strlen(str) >= sizeof(lowstr))
+ elog(ERROR, "Bad date external representation (too long) '%s'", str);
+
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0))
elog(ERROR, "Bad date external representation '%s'", str);
int dtype;
int ftype[MAXDATEFIELDS];
+ if (strlen(str) >= sizeof(lowstr))
+ elog(ERROR, "Bad time external representation (too long) '%s'", str);
+
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, NULL) != 0))
elog(ERROR, "Bad time external representation '%s'", str);
int dtype;
int ftype[MAXDATEFIELDS];
+ if (strlen(str) >= sizeof(lowstr))
+ elog(ERROR, "Bad time with time zone external representation"
+ " (too long) '%s'", str);
+
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
elog(ERROR, "Bad time external representation '%s'", str);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.91 2001/10/25 05:49:44 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.91.2.1 2002/08/22 05:27:41 momjian Exp $
*
* NOTES
*
* XXX is there a better way to get local timezone string w/o
* tzname? - tgl 97/03/18
*/
- strftime(CTZName, MAXTZLEN, "%Z", tm);
+ strftime(CTZName, MAXTZLEN + 1, "%Z", tm);
#endif
/*
* XXX FreeBSD man pages indicate that this should work - thomas
* 1998-12-12
*/
- strcpy(CTZName, tm->tm_zone);
+ StrNCpy(CTZName, tm->tm_zone, MAXTZLEN + 1);
#elif defined(HAVE_INT_TIMEZONE)
tm = localtime(&now);
CDayLight = tm->tm_isdst;
CTimeZone = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
- strcpy(CTZName, tzname[tm->tm_isdst]);
+ StrNCpy(CTZName, tzname[tm->tm_isdst], MAXTZLEN + 1);
#else /* neither HAVE_TM_ZONE nor
* HAVE_INT_TIMEZONE */
CTimeZone = tb.timezone * 60;
* XXX does this work to get the local timezone string in V7? -
* tgl 97/03/18
*/
- strftime(CTZName, MAXTZLEN, "%Z", localtime(&now));
+ strftime(CTZName, MAXTZLEN + 1, "%Z", localtime(&now));
#endif
}
* XXX is there a better way to get local timezone string w/o
* tzname? - tgl 97/03/18
*/
- strftime(CTZName, MAXTZLEN, "%Z", tm);
+ strftime(CTZName, MAXTZLEN + 1, "%Z", tm);
#endif
/*
* XXX FreeBSD man pages indicate that this should work - thomas
* 1998-12-12
*/
- strcpy(CTZName, tm->tm_zone);
+ StrNCpy(CTZName, tm->tm_zone, MAXTZLEN + 1);
#elif defined(HAVE_INT_TIMEZONE)
tm = localtime(&now);
CDayLight = tm->tm_isdst;
CTimeZone = ((tm->tm_isdst > 0) ? (TIMEZONE_GLOBAL - 3600) : TIMEZONE_GLOBAL);
- strcpy(CTZName, tzname[tm->tm_isdst]);
+ StrNCpy(CTZName, tzname[tm->tm_isdst], MAXTZLEN + 1);
#else /* neither HAVE_TM_ZONE nor
* HAVE_INT_TIMEZONE */
CTimeZone = tb.timezone * 60;
* XXX does this work to get the local timezone string in V7? -
* tgl 97/03/18
*/
- strftime(CTZName, MAXTZLEN, "%Z", localtime(&now));
+ strftime(CTZName, MAXTZLEN + 1, "%Z", localtime(&now));
#endif
};
int nf,
ftype[MAXDATEFIELDS];
- if (strlen(str) > MAXDATELEN)
- elog(ERROR, "Bad (length) abstime external representation '%s'", str);
+ if (strlen(str) >= sizeof(lowstr))
+ elog(ERROR, "Bad abstime external representation '%s' (too long)", str);
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
ftype[MAXDATEFIELDS];
char lowstr[MAXDATELEN + 1];
- if (strlen(str) > MAXDATELEN)
- elog(ERROR, "Bad (length) reltime external representation '%s'", str);
+ if (strlen(str) >= sizeof(lowstr))
+ elog(ERROR, "Bad reltime external representation '%s' (too long)", str);
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateDelta(field, ftype, nf, &dtype, tm, &fsec) != 0))
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.37 2002/01/08 17:03:41 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.37.2.1 2002/08/22 05:27:41 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifdef MULTIBYTE
bytelen = pg_database_encoding_max_length() * len;
+
+ /* check for integer overflow */
+ if (len != 0 && bytelen / pg_database_encoding_max_length() != len)
+ elog(ERROR, "Requested length too large");
+
ret = (text *) palloc(VARHDRSZ + bytelen);
#else
ret = (text *) palloc(VARHDRSZ + len);
#ifdef MULTIBYTE
bytelen = pg_database_encoding_max_length() * len;
+
+ /* Check for integer overflow */
+ if (len != 0 && bytelen / pg_database_encoding_max_length() != len)
+ elog(ERROR, "Requested length too large");
+
ret = (text *) palloc(VARHDRSZ + bytelen);
#else
ret = (text *) palloc(VARHDRSZ + len);
slen = (VARSIZE(string) - VARHDRSZ);
tlen = (VARHDRSZ + (count * slen));
+ /* Check for integer overflow */
+ if (slen != 0 && count != 0)
+ {
+ int check = count * slen;
+ int check2 = check + VARHDRSZ;
+
+ if ((check / slen) != count || check2 <= check)
+ elog(ERROR, "Requested buffer is too large.");
+ }
+
result = (text *) palloc(tlen);
VARATT_SIZEP(result) = tlen;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.62.2.1 2002/03/05 03:45:43 ishii Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.62.2.2 2002/08/22 05:27:41 momjian Exp $
*
*-------------------------------------------------------------------------
*/
int nf;
char *field[MAXDATEFIELDS];
int ftype[MAXDATEFIELDS];
- char lowstr[MAXDATELEN + 1];
+ char lowstr[MAXDATELEN + MAXDATEFIELDS];
+
+ if (strlen(str) >= sizeof(lowstr))
+ elog(ERROR, "Bad timestamp external representation (too long) '%s'", str);
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
int nf;
char *field[MAXDATEFIELDS];
int ftype[MAXDATEFIELDS];
- char lowstr[MAXDATELEN + 1];
+ char lowstr[MAXDATELEN + MAXDATEFIELDS];
+
+ if (strlen(str) >= sizeof(lowstr))
+ elog(ERROR, "Bad timestamp with time zone"
+ " external representation (too long) '%s'", str);
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
int nf;
char *field[MAXDATEFIELDS];
int ftype[MAXDATEFIELDS];
- char lowstr[MAXDATELEN + 1];
+ char lowstr[MAXDATELEN + MAXDATEFIELDS];
+
+ if (strlen(str) >= sizeof(lowstr))
+ elog(ERROR, "Bad interval external representation (too long) '%s'", str);
tm->tm_year = 0;
tm->tm_mon = 0;