Skip to content

Commit 4749e91

Browse files
committed
Fix insufficient check for overflow in tm2abstime(), per report from jw.
1 parent 37c443e commit 4749e91

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/backend/utils/adt/nabstime.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.140 2005/07/22 03:46:33 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.141 2005/07/22 19:55:50 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -29,7 +29,7 @@
2929
#include "utils/builtins.h"
3030
#include "utils/nabstime.h"
3131

32-
#define MIN_DAYNUM -24856 /* December 13, 1901 */
32+
#define MIN_DAYNUM (-24856) /* December 13, 1901 */
3333
#define MAX_DAYNUM 24854 /* January 18, 2038 */
3434

3535
#define INVALID_RELTIME_STR "Undefined RelTime"
@@ -201,9 +201,12 @@ tm2abstime(struct pg_tm *tm, int tz)
201201
/* convert to seconds */
202202
sec = tm->tm_sec + tz + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
203203

204-
/* check for overflow */
205-
if ((day == MAX_DAYNUM && sec < 0) ||
206-
(day == MIN_DAYNUM && sec > 0))
204+
/*
205+
* check for overflow. We need a little slop here because the H/M/S plus
206+
* TZ offset could add up to more than 1 day.
207+
*/
208+
if ((day >= MAX_DAYNUM-10 && sec < 0) ||
209+
(day <= MIN_DAYNUM+10 && sec > 0))
207210
return INVALID_ABSTIME;
208211

209212
/* check for reserved values (e.g. "current" on edge of usual range */

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