Skip to content

Commit c436e8d

Browse files
committed
IcingaDB::TimestampToMilliseconds(): limit output to four year digits
Too high timestamps may overflow uint64_t (and the YYYY format) and negative ones don't fit into uint64_t. Those may crash our Go daemon.
1 parent 01d3a1d commit c436e8d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/icingadb/icingadb-utility.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,21 @@ String IcingaDB::GetLowerCaseTypeNameDB(const ConfigObject::Ptr& obj)
245245
}
246246

247247
long long IcingaDB::TimestampToMilliseconds(double timestamp) {
248+
// In addition to the limits of the Icinga DB MySQL (0 - 2^64) and PostgreSQL (0 - 2^63) schemata,
249+
// years not fitting in YYYY may cause problems, see e.g. https://github.com/golang/go/issues/4556.
250+
// RFC 3339: "All dates and times are assumed to be (...) somewhere between 0000AD and 9999AD."
251+
//
252+
// The below upper limit includes a safety buffer to make sure the timestamp is within 9999AD in all time zones:
253+
// $ date -ud @253402214400
254+
// Fri Dec 31 00:00:00 UTC 9999
255+
// $ TZ=Asia/Vladivostok date -d @253402214400
256+
// Fri Dec 31 10:00:00 +10 9999
257+
// $ TZ=America/Juneau date -d @253402214400
258+
// Thu Dec 30 15:00:00 AKST 9999
259+
if (timestamp <= 0.0 || timestamp > 253402214400.0) {
260+
return 0;
261+
}
262+
248263
return static_cast<long long>(timestamp * 1000);
249264
}
250265

0 commit comments

Comments
 (0)