Skip to content

Commit

Permalink
Update dummy keychain patch to avoid potential segfaults
Browse files Browse the repository at this point in the history
Under certain circumstances, use of the dummy keychain patch can cause fairly
frequent segfaults when NFD creates UDP multicast faces. These appear to have
been due to issues with using using function-local static variables in a way that
was not thread safe. After some collaboration with Alex Afanasyev regarding finding
a cause, we landed on this fix which adjusts the offending code.

Co-Authored-By: Alex Afanasyev <[email protected]>
Change-Id: Iadb812cb8a3d87b83421b7fa109dd539f0c7065f
  • Loading branch information
awlane and cawka committed Oct 9, 2023
1 parent 273e80f commit af975e5
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions util/patches/ndn-cxx-dummy-keychain.patch
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ index 16f6c421..d01696e9 100644

diff --git a/ndn-cxx/util/dummy-keychain.cpp b/ndn-cxx/util/dummy-keychain.cpp
new file mode 100644
index 00000000..dbf399dc
index 00000000..9421fb24
--- /dev/null
+++ b/ndn-cxx/util/dummy-keychain.cpp
@@ -0,0 +1,352 @@
@@ -0,0 +1,348 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
Expand Down Expand Up @@ -164,11 +164,12 @@ index 00000000..dbf399dc
+Buffer
+DummyPib::getKeyBits(const Name& keyName) const
+{
+ static auto cert = [] {
+ typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
+ arrayStream
+ is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
+ auto cert = io::load<Certificate>(is, io::BASE64);
+ return Buffer(cert->getContent().value(), cert->getContent().value_size());
+ arrayStream is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
+ return io::loadTlv<Certificate>(is, io::BASE64);
+ }();
+ return Buffer(cert.getContent().value(), cert.getContent().value_size());
+}
+
+std::set<Name>
Expand Down Expand Up @@ -209,15 +210,12 @@ index 00000000..dbf399dc
+Certificate
+DummyPib::getCertificate(const Name& certificateName) const
+{
+ static shared_ptr<Certificate> cert = nullptr;
+ if (cert == nullptr) {
+ static auto cert = [] {
+ typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
+ arrayStream
+ is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
+ cert = io::load<Certificate>(is, io::BASE64);
+ }
+
+ return *cert;
+ arrayStream is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
+ return io::loadTlv<Certificate>(is, io::BASE64);
+ }();
+ return cert;
+}
+
+std::set<Name>
Expand All @@ -236,15 +234,12 @@ index 00000000..dbf399dc
+Certificate
+DummyPib::getDefaultCertificateOfKey(const Name& keyName) const
+{
+ static shared_ptr<Certificate> cert = nullptr;
+ if (cert == nullptr) {
+ static auto cert = [] {
+ typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream;
+ arrayStream
+ is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
+ cert = io::load<Certificate>(is, io::BASE64);
+ }
+
+ return *cert;
+ arrayStream is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT));
+ return io::loadTlv<Certificate>(is, io::BASE64);
+ }();
+ return cert;
+}
+
+std::string
Expand All @@ -267,7 +262,8 @@ index 00000000..dbf399dc
+ConstBufferPtr
+DummyKeyHandle::doSign(DigestAlgorithm digestAlgorithm, const InputBuffers& bufs) const
+{
+ return make_shared<Buffer>(DUMMY_SIGNATURE, sizeof(DUMMY_SIGNATURE));
+ thread_local auto buff = make_shared<Buffer>(DUMMY_SIGNATURE, sizeof(DUMMY_SIGNATURE));
+ return buff;
+}
+
+bool
Expand Down

0 comments on commit af975e5

Please sign in to comment.