Skip to content

Commit 2078e38

Browse files
committed
Fix range check in date_recv that tried to limit accepted values to only
those accepted by date_in(). I confused julian day numbers and number of days since the postgres epoch 2000-01-01 in the original patch. I just noticed that it's still easy to get such out-of-range values into the database using to_date or +- operators, but this patch doesn't do anything about those functions. Per report from James Pye.
1 parent 9f2ee8f commit 2078e38

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/backend/utils/adt/date.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.148 2009/09/04 11:20:22 heikki Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.149 2009/10/26 16:13:11 heikki Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -208,7 +208,8 @@ date_recv(PG_FUNCTION_ARGS)
208208
result = (DateADT) pq_getmsgint(buf, sizeof(DateADT));
209209

210210
/* Limit to the same range that date_in() accepts. */
211-
if (result < 0 || result > JULIAN_MAX)
211+
if (result < -POSTGRES_EPOCH_JDATE ||
212+
result >= JULIAN_MAX - POSTGRES_EPOCH_JDATE)
212213
ereport(ERROR,
213214
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
214215
errmsg("date out of range")));

src/include/utils/datetime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $PostgreSQL: pgsql/src/include/utils/datetime.h,v 1.76 2009/09/04 11:20:23 heikki Exp $
12+
* $PostgreSQL: pgsql/src/include/utils/datetime.h,v 1.77 2009/10/26 16:13:11 heikki Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -262,7 +262,7 @@ extern const int day_tab[2][13];
262262
|| (((m) == JULIAN_MINMONTH) && ((d) >= JULIAN_MINDAY))))) \
263263
&& ((y) < JULIAN_MAXYEAR))
264264

265-
#define JULIAN_MAX (2145031948) /* == date2j(JULIAN_MAXYEAR, 1 ,1) */
265+
#define JULIAN_MAX (2147483494) /* == date2j(JULIAN_MAXYEAR, 1 ,1) */
266266

267267
/* Julian-date equivalents of Day 0 in Unix and Postgres reckoning */
268268
#define UNIX_EPOCH_JDATE 2440588 /* == date2j(1970, 1, 1) */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy