Prevent integer overflow within the integer-datetimes version of
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 23 Jan 2008 21:26:20 +0000 (21:26 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 23 Jan 2008 21:26:20 +0000 (21:26 +0000)
TimestampTzPlusMilliseconds.  An integer argument of more than INT_MAX/1000
milliseconds (ie, about 35 minutes) would provoke a wrong result, resulting
in incorrect enforcement of statement_timestamp values larger than that.
Bug was introduced in my rewrite of 2006-06-20, which fixed some other
overflow risks, but missed this one :-(  Per report from Elein.

src/include/utils/timestamp.h

index 6eec76d8e0f4e54efd649c01dd68ce435ebbd760..e8603ecbf9a0d6e57772a959e5d1aaa6d5a6e972 100644 (file)
@@ -182,7 +182,7 @@ typedef double fsec_t;
 #define INTERVAL_RANGE(t) (((t) >> 16) & INTERVAL_RANGE_MASK)
 
 #ifdef HAVE_INT64_TIMESTAMP
-#define TimestampTzPlusMilliseconds(tz,ms) ((tz) + ((ms) * 1000))
+#define TimestampTzPlusMilliseconds(tz,ms) ((tz) + ((ms) * (int64) 1000))
 #else
 #define TimestampTzPlusMilliseconds(tz,ms) ((tz) + ((ms) / 1000.0))
 #endif