Skip to content

Commit

Permalink
IcingaDB::TimestampToMilliseconds(): limit output to four year digits
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Al2Klimov committed Sep 26, 2024
1 parent 01d3a1d commit c436e8d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/icingadb/icingadb-utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,21 @@ String IcingaDB::GetLowerCaseTypeNameDB(const ConfigObject::Ptr& obj)
}

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

return static_cast<long long>(timestamp * 1000);
}

Expand Down

0 comments on commit c436e8d

Please sign in to comment.