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

Commit157e17e

Browse files
committed
Add an upper limit to IS_VALID_JULIAN() to defend against overflow in
date2j(). This ensures we give reasonable errors instead of bizarrebehavior for input dates far in the future.
1 parent0347d31 commit157e17e

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

‎src/include/utils/datetime.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $Id: datetime.h,v 1.40 2003/07/1700:55:37 tgl Exp $
12+
* $Id: datetime.h,v 1.41 2003/07/1722:28:42 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -237,17 +237,21 @@ extern intday_tab[2][13];
237237
#defineisleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
238238

239239
/* Julian date support for date2j() and j2date()
240-
* Set the minimum year to one greater than the year of the first valid day
241-
*to avoid having to check year and day both. - tgl 97/05/08
240+
*
241+
* IS_VALID_JULIAN checks the minimum date exactly, but is a bit sloppy
242+
* about the maximum, since it's far enough out to not be especially
243+
* interesting.
242244
*/
243245

244246
#defineJULIAN_MINYEAR (-4713)
245247
#defineJULIAN_MINMONTH (11)
246248
#defineJULIAN_MINDAY (24)
249+
#defineJULIAN_MAXYEAR (5874898)
247250

248-
#defineIS_VALID_JULIAN(y,m,d) (((y) > JULIAN_MINYEAR) \
249-
|| (((y) == JULIAN_MINYEAR) && (((m) > JULIAN_MINMONTH) \
250-
|| (((m) == JULIAN_MINMONTH) && ((d) >= JULIAN_MINDAY)))))
251+
#defineIS_VALID_JULIAN(y,m,d) ((((y) > JULIAN_MINYEAR) \
252+
|| (((y) == JULIAN_MINYEAR) && (((m) > JULIAN_MINMONTH) \
253+
|| (((m) == JULIAN_MINMONTH) && ((d) >= JULIAN_MINDAY))))) \
254+
&& ((y) < JULIAN_MAXYEAR))
251255

252256
#defineUTIME_MINYEAR (1901)
253257
#defineUTIME_MINMONTH (12)

‎src/interfaces/ecpg/pgtypeslib/dt.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,21 @@ extern intday_tab[2][13];
232232
#defineisleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
233233

234234
/* Julian date support for date2j() and j2date()
235-
* Set the minimum year to one greater than the year of the first valid day
236-
*to avoid having to check year and day both. - tgl 97/05/08
235+
*
236+
* IS_VALID_JULIAN checks the minimum date exactly, but is a bit sloppy
237+
* about the maximum, since it's far enough out to not be especially
238+
* interesting.
237239
*/
238240

239241
#defineJULIAN_MINYEAR (-4713)
240242
#defineJULIAN_MINMONTH (11)
241243
#defineJULIAN_MINDAY (24)
244+
#defineJULIAN_MAXYEAR (5874898)
242245

243-
#defineIS_VALID_JULIAN(y,m,d) (((y) > JULIAN_MINYEAR) \
244-
|| (((y) == JULIAN_MINYEAR) && (((m) > JULIAN_MINMONTH) \
245-
|| (((m) == JULIAN_MINMONTH) && ((d) >= JULIAN_MINDAY)))))
246+
#defineIS_VALID_JULIAN(y,m,d) ((((y) > JULIAN_MINYEAR) \
247+
|| (((y) == JULIAN_MINYEAR) && (((m) > JULIAN_MINMONTH) \
248+
|| (((m) == JULIAN_MINMONTH) && ((d) >= JULIAN_MINDAY))))) \
249+
&& ((y) < JULIAN_MAXYEAR))
246250

247251
#defineUTIME_MINYEAR (1901)
248252
#defineUTIME_MINMONTH (12)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp