table: fix Pit::erase crash when Interest name contains implicit digest
refs #3608
Change-Id: I41e0cd327b9dcc5f2d3a83f4cebff40c2d302fc1
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index ece0b40..e432c4e 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.hpp
@@ -38,6 +38,8 @@
class Entry;
} // namespace name_tree
+class Pit;
+
namespace pit {
/** \brief an unordered collection of in-records
@@ -198,6 +200,7 @@
friend class nfd::NameTree;
friend class nfd::name_tree::Entry;
+ friend class nfd::Pit;
};
inline const Interest&
diff --git a/daemon/table/pit.cpp b/daemon/table/pit.cpp
index 12a21bd..ae5a5cd 100644
--- a/daemon/table/pit.cpp
+++ b/daemon/table/pit.cpp
@@ -113,7 +113,7 @@
void
Pit::erase(shared_ptr<pit::Entry> pitEntry)
{
- shared_ptr<name_tree::Entry> nameTreeEntry = m_nameTree.get(*pitEntry);
+ shared_ptr<name_tree::Entry> nameTreeEntry = pitEntry->m_nameTreeEntry;
BOOST_ASSERT(static_cast<bool>(nameTreeEntry));
nameTreeEntry->erasePitEntry(pitEntry);
diff --git a/tests/daemon/table/pit.t.cpp b/tests/daemon/table/pit.t.cpp
index 01f063d..80e31d3 100644
--- a/tests/daemon/table/pit.t.cpp
+++ b/tests/daemon/table/pit.t.cpp
@@ -347,6 +347,34 @@
BOOST_CHECK_EQUAL(nameTree.size(), nNameTreeEntriesBefore);
}
+BOOST_AUTO_TEST_CASE(EraseWithFullName)
+{
+ shared_ptr<Data> data = makeData("/test");
+ shared_ptr<Interest> interest = makeInterest(data->getFullName());
+
+ NameTree nameTree(16);
+ Pit pit(nameTree);
+
+ BOOST_CHECK_EQUAL(pit.size(), 0);
+
+ BOOST_CHECK_EQUAL(pit.insert(*interest).second, true);
+ BOOST_CHECK_EQUAL(pit.size(), 1);
+ BOOST_CHECK(pit.find(*interest) != nullptr);
+
+ BOOST_CHECK_EQUAL(pit.insert(*interest).second, false);
+ BOOST_CHECK_EQUAL(pit.size(), 1);
+ shared_ptr<pit::Entry> pitEntry = pit.find(*interest);
+ BOOST_REQUIRE(pitEntry != nullptr);
+
+ pit.erase(pitEntry);
+ BOOST_CHECK_EQUAL(pit.size(), 0);
+ BOOST_CHECK(pit.find(*interest) == nullptr);
+
+ BOOST_CHECK_EQUAL(pit.insert(*interest).second, true);
+ BOOST_CHECK_EQUAL(pit.size(), 1);
+ BOOST_CHECK(pit.find(*interest) != nullptr);
+}
+
BOOST_AUTO_TEST_CASE(FindAllDataMatches)
{
Name nameA ("ndn:/A");