aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-07-17 22:28:42 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-07-17 22:28:42 +0000
commit157e17e20d75ddcc83eb839822d85f806cf3d2a3 (patch)
tree4fece8cec3b24ec2143922d4b8b81ea38d27fe1b /src
parent0347d310d70326f29133fb1dab09a7d5e1c6d7c4 (diff)
downloadpostgresql-157e17e20d75ddcc83eb839822d85f806cf3d2a3.tar.gz
postgresql-157e17e20d75ddcc83eb839822d85f806cf3d2a3.zip
Add an upper limit to IS_VALID_JULIAN() to defend against overflow in
date2j(). This ensures we give reasonable errors instead of bizarre behavior for input dates far in the future.
Diffstat (limited to 'src')
-rw-r--r--src/include/utils/datetime.h16
-rw-r--r--src/interfaces/ecpg/pgtypeslib/dt.h14
2 files changed, 19 insertions, 11 deletions
diff --git a/src/include/utils/datetime.h b/src/include/utils/datetime.h
index 4a9443e1750..6fe4723bbee 100644
--- a/src/include/utils/datetime.h
+++ b/src/include/utils/datetime.h
@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: datetime.h,v 1.40 2003/07/17 00:55:37 tgl Exp $
+ * $Id: datetime.h,v 1.41 2003/07/17 22:28:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -237,17 +237,21 @@ extern int day_tab[2][13];
#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
/* Julian date support for date2j() and j2date()
- * Set the minimum year to one greater than the year of the first valid day
- * to avoid having to check year and day both. - tgl 97/05/08
+ *
+ * IS_VALID_JULIAN checks the minimum date exactly, but is a bit sloppy
+ * about the maximum, since it's far enough out to not be especially
+ * interesting.
*/
#define JULIAN_MINYEAR (-4713)
#define JULIAN_MINMONTH (11)
#define JULIAN_MINDAY (24)
+#define JULIAN_MAXYEAR (5874898)
-#define IS_VALID_JULIAN(y,m,d) (((y) > JULIAN_MINYEAR) \
- || (((y) == JULIAN_MINYEAR) && (((m) > JULIAN_MINMONTH) \
- || (((m) == JULIAN_MINMONTH) && ((d) >= JULIAN_MINDAY)))))
+#define IS_VALID_JULIAN(y,m,d) ((((y) > JULIAN_MINYEAR) \
+ || (((y) == JULIAN_MINYEAR) && (((m) > JULIAN_MINMONTH) \
+ || (((m) == JULIAN_MINMONTH) && ((d) >= JULIAN_MINDAY))))) \
+ && ((y) < JULIAN_MAXYEAR))
#define UTIME_MINYEAR (1901)
#define UTIME_MINMONTH (12)
diff --git a/src/interfaces/ecpg/pgtypeslib/dt.h b/src/interfaces/ecpg/pgtypeslib/dt.h
index 185f0b0c948..a4d6f044a91 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt.h
+++ b/src/interfaces/ecpg/pgtypeslib/dt.h
@@ -232,17 +232,21 @@ extern int day_tab[2][13];
#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
/* Julian date support for date2j() and j2date()
- * Set the minimum year to one greater than the year of the first valid day
- * to avoid having to check year and day both. - tgl 97/05/08
+ *
+ * IS_VALID_JULIAN checks the minimum date exactly, but is a bit sloppy
+ * about the maximum, since it's far enough out to not be especially
+ * interesting.
*/
#define JULIAN_MINYEAR (-4713)
#define JULIAN_MINMONTH (11)
#define JULIAN_MINDAY (24)
+#define JULIAN_MAXYEAR (5874898)
-#define IS_VALID_JULIAN(y,m,d) (((y) > JULIAN_MINYEAR) \
- || (((y) == JULIAN_MINYEAR) && (((m) > JULIAN_MINMONTH) \
- || (((m) == JULIAN_MINMONTH) && ((d) >= JULIAN_MINDAY)))))
+#define IS_VALID_JULIAN(y,m,d) ((((y) > JULIAN_MINYEAR) \
+ || (((y) == JULIAN_MINYEAR) && (((m) > JULIAN_MINMONTH) \
+ || (((m) == JULIAN_MINMONTH) && ((d) >= JULIAN_MINDAY))))) \
+ && ((y) < JULIAN_MAXYEAR))
#define UTIME_MINYEAR (1901)
#define UTIME_MINMONTH (12)