Skip to content

Commit f1ba94b

Browse files
committed
Fix portability issues in recently added make_timestamp/make_interval code.
Explicitly reject infinity/NaN inputs, rather than just assuming that something else will do it for us. Per buildfarm. While at it, make some over-parenthesized and under-legible code more readable.
1 parent 8cf0ad1 commit f1ba94b

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/backend/utils/adt/timestamp.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,14 @@ make_timestamp_internal(int year, int month, int day,
597597

598598
date = date2j(tm.tm_year, tm.tm_mon, tm.tm_mday) - POSTGRES_EPOCH_JDATE;
599599

600-
/* This should match the checks in DecodeTimeOnly */
600+
/*
601+
* This should match the checks in DecodeTimeOnly, except that since we're
602+
* dealing with a float "sec" value, we also explicitly reject NaN. (An
603+
* infinity input should get rejected by the range comparisons, but we
604+
* can't be sure how those will treat a NaN.)
605+
*/
601606
if (hour < 0 || min < 0 || min > MINS_PER_HOUR - 1 ||
607+
isnan(sec) ||
602608
sec < 0 || sec > SECS_PER_MINUTE ||
603609
hour > HOURS_PER_DAY ||
604610
/* test for > 24:00:00 */
@@ -1463,23 +1469,25 @@ make_interval(PG_FUNCTION_ARGS)
14631469
double secs = PG_GETARG_FLOAT8(6);
14641470
Interval *result;
14651471

1472+
/*
1473+
* Reject out-of-range inputs. We really ought to check the integer
1474+
* inputs as well, but it's not entirely clear what limits to apply.
1475+
*/
1476+
if (isinf(secs) || isnan(secs))
1477+
ereport(ERROR,
1478+
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1479+
errmsg("interval out of range")));
1480+
14661481
result = (Interval *) palloc(sizeof(Interval));
14671482
result->month = years * MONTHS_PER_YEAR + months;
14681483
result->day = weeks * 7 + days;
14691484

1485+
secs += hours * (double) SECS_PER_HOUR + mins * (double) SECS_PER_MINUTE;
1486+
14701487
#ifdef HAVE_INT64_TIMESTAMP
1471-
result->time = ((((hours * INT64CONST(60)) +
1472-
mins) * INT64CONST(60)) +
1473-
secs) * USECS_PER_SEC;
1488+
result->time = (int64) (secs * USECS_PER_SEC);
14741489
#else
1475-
result->time = (((hours * (double) MINS_PER_HOUR) +
1476-
mins) * (double) SECS_PER_MINUTE) +
1477-
secs;
1478-
#endif
1479-
1480-
#ifdef NOT_USED
1481-
/* this is a no-op for negative typmods */
1482-
AdjustIntervalForTypmod(result, -1);
1490+
result->time = secs;
14831491
#endif
14841492

14851493
PG_RETURN_INTERVAL_P(result);

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