table: prevent integer overflow in pit::FaceRecord
refs #4979
Change-Id: Iacd5abdfc8ae4530364e3fa590778a234140b7ed
diff --git a/daemon/table/pit-face-record.cpp b/daemon/table/pit-face-record.cpp
index d58ec96..639f424 100644
--- a/daemon/table/pit-face-record.cpp
+++ b/daemon/table/pit-face-record.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,6 +28,9 @@
namespace nfd {
namespace pit {
+// Impose a maximum lifetime to prevent integer overflow when calculating m_expiry.
+static const time::milliseconds MAX_LIFETIME{10_days};
+
void
FaceRecord::update(const Interest& interest)
{
@@ -35,9 +38,7 @@
m_lastRenewed = time::steady_clock::now();
auto lifetime = interest.getInterestLifetime();
- if (lifetime < 0_ms) {
- lifetime = ndn::DEFAULT_INTEREST_LIFETIME;
- }
+ lifetime = std::min(lifetime, MAX_LIFETIME);
m_expiry = m_lastRenewed + lifetime;
}