src: Check validity of FaceURIs while loading conf
refs: #2070
Change-Id: I2278ab0a6367910495208a48c801f3af83bd43ec
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index b3067a3..9a100ec 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -25,6 +25,7 @@
#include <fstream>
#include <ndn-cxx/name.hpp>
+#include <ndn-cxx/util/face-uri.hpp>
// boost needs to be included after ndn-cxx, otherwise there will be conflict with _1, _2, ...
#include <boost/algorithm/string.hpp>
@@ -499,6 +500,14 @@
ConfigSection CommandAttriTree = tn->second;
std::string name = CommandAttriTree.get<std::string>("name");
std::string faceUri = CommandAttriTree.get<std::string>("face-uri");
+
+ ndn::util::FaceUri uri;
+
+ if (!uri.parse(faceUri)) {
+ std::cerr << "Malformed face-uri <" << faceUri << "> for " << name << std::endl;
+ return false;
+ }
+
double linkCost = CommandAttriTree.get<double>("link-cost",
Adjacent::DEFAULT_LINK_COST);
ndn::Name neighborName(name);
@@ -671,4 +680,4 @@
return true;
}
-} // namespace nlsr
\ No newline at end of file
+} // namespace nlsr
diff --git a/tests/test-conf-file-processor.cpp b/tests/test-conf-file-processor.cpp
index 25d1433..ab24215 100644
--- a/tests/test-conf-file-processor.cpp
+++ b/tests/test-conf-file-processor.cpp
@@ -333,6 +333,27 @@
verifyOutputLog4cxx(EXPECTED, sizeof(EXPECTED) / sizeof(std::string));
}
+BOOST_AUTO_TEST_CASE(MalformedUri)
+{
+ const std::string MALFORMED_URI =
+ "neighbors\n"
+ "{\n"
+ " hello-retries 3\n"
+ " hello-timeout 1\n"
+ " hello-interval 60\n\n"
+ " adj-lsa-build-interval 3\n"
+ " first-hello-interval 6\n"
+ " neighbor\n"
+ " {\n"
+ " name /ndn/memphis.edu/cs/castor\n"
+ " face-uri udp4:malformed-uri\n"
+ " link-cost 20\n"
+ " }\n"
+ "}\n\n";
+
+ BOOST_CHECK_EQUAL(processConfigurationString(MALFORMED_URI), false);
+}
+
BOOST_AUTO_TEST_CASE(Hyperbolic)
{
processConfigurationString(CONFIG_HYPERBOLIC);
@@ -393,4 +414,4 @@
BOOST_AUTO_TEST_SUITE_END()
} //namespace test
-} //namespace nlsr
\ No newline at end of file
+} //namespace nlsr