Skip to content

Commit 8c05158

Browse files
committed
IcingaDB::TimestampToMilliseconds(): limit output to [1970..8307] AD
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 cb945fe commit 8c05158

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/icingadb/icingadb-utility.cpp

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

247247
long long IcingaDB::TimestampToMilliseconds(double timestamp) {
248+
// In addition to the limit of 2^63 of the Icinga DB PostgreSQL schema,
249+
// negative timestamps or years with more than four digits may cause problems.
250+
if (timestamp <= 0.0 || timestamp > 2e11 /* 8307 AD */) {
251+
return 0;
252+
}
253+
248254
return static_cast<long long>(timestamp * 1000);
249255
}
250256

0 commit comments

Comments
 (0)