mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-01 13:41:17 +02:00
Fix insufficient check for overflow in tm2abstime(), per report from jw.
This commit is contained in:
parent
37c443eefd
commit
4749e914ae
@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.140 2005/07/22 03:46:33 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.141 2005/07/22 19:55:50 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -29,7 +29,7 @@
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/nabstime.h"
|
||||
|
||||
#define MIN_DAYNUM -24856 /* December 13, 1901 */
|
||||
#define MIN_DAYNUM (-24856) /* December 13, 1901 */
|
||||
#define MAX_DAYNUM 24854 /* January 18, 2038 */
|
||||
|
||||
#define INVALID_RELTIME_STR "Undefined RelTime"
|
||||
@ -201,9 +201,12 @@ tm2abstime(struct pg_tm *tm, int tz)
|
||||
/* convert to seconds */
|
||||
sec = tm->tm_sec + tz + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
|
||||
|
||||
/* check for overflow */
|
||||
if ((day == MAX_DAYNUM && sec < 0) ||
|
||||
(day == MIN_DAYNUM && sec > 0))
|
||||
/*
|
||||
* check for overflow. We need a little slop here because the H/M/S plus
|
||||
* TZ offset could add up to more than 1 day.
|
||||
*/
|
||||
if ((day >= MAX_DAYNUM-10 && sec < 0) ||
|
||||
(day <= MIN_DAYNUM+10 && sec > 0))
|
||||
return INVALID_ABSTIME;
|
||||
|
||||
/* check for reserved values (e.g. "current" on edge of usual range */
|
||||
|
Loading…
Reference in New Issue
Block a user