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 #include +#include // boost needs to be included after ndn-cxx, otherwise there will be conflict with _1, _2, ... #include @@ -499,6 +500,14 @@ ConfFileProcessor::processConfSectionNeighbors(const ConfigSection& section) ConfigSection CommandAttriTree = tn->second; std::string name = CommandAttriTree.get("name"); std::string faceUri = CommandAttriTree.get("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("link-cost", Adjacent::DEFAULT_LINK_COST); ndn::Name neighborName(name); @@ -671,4 +680,4 @@ ConfFileProcessor::processConfSectionSecurity(const ConfigSection& section) 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 @@ BOOST_AUTO_TEST_CASE(Log4cxxTestCase) 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_CASE(OutOfRangeValue) BOOST_AUTO_TEST_SUITE_END() } //namespace test -} //namespace nlsr \ No newline at end of file +} //namespace nlsr