face: Gracefully handle tlv::Error when received TLV block is malformed
Change-Id: I954b13d0e26fec7bc7fe23edcbc015dfac654ef8
Refs: #1494
diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp
index d0d42db..46dbcf6 100644
--- a/daemon/face/face.cpp
+++ b/daemon/face/face.cpp
@@ -90,24 +90,29 @@
bool
Face::decodeAndDispatchInput(const Block& element)
{
- /// \todo Ensure lazy field decoding process
+ try {
+ /// \todo Ensure lazy field decoding process
- if (element.type() == tlv::Interest)
- {
- shared_ptr<Interest> i = make_shared<Interest>();
- i->wireDecode(element);
- this->onReceiveInterest(*i);
- }
- else if (element.type() == tlv::Data)
- {
- shared_ptr<Data> d = make_shared<Data>();
- d->wireDecode(element);
- this->onReceiveData(*d);
- }
- else
+ if (element.type() == tlv::Interest)
+ {
+ shared_ptr<Interest> i = make_shared<Interest>();
+ i->wireDecode(element);
+ this->onReceiveInterest(*i);
+ }
+ else if (element.type() == tlv::Data)
+ {
+ shared_ptr<Data> d = make_shared<Data>();
+ d->wireDecode(element);
+ this->onReceiveData(*d);
+ }
+ else
+ return false;
+
+ return true;
+ }
+ catch (tlv::Error&) {
return false;
-
- return true;
+ }
}
} //namespace nfd
diff --git a/daemon/face/local-face.hpp b/daemon/face/local-face.hpp
index 118dce7..e1c34c3 100644
--- a/daemon/face/local-face.hpp
+++ b/daemon/face/local-face.hpp
@@ -138,47 +138,52 @@
inline bool
LocalFace::decodeAndDispatchInput(const Block& element)
{
- const Block& payload = ndn::nfd::LocalControlHeader::getPayload(element);
+ try {
+ const Block& payload = ndn::nfd::LocalControlHeader::getPayload(element);
- // If received LocalControlHeader, but it is not enabled on the face
- if ((&payload != &element) && !this->isLocalControlHeaderEnabled())
+ // If received LocalControlHeader, but it is not enabled on the face
+ if ((&payload != &element) && !this->isLocalControlHeaderEnabled())
+ return false;
+
+ if (payload.type() == tlv::Interest)
+ {
+ shared_ptr<Interest> i = make_shared<Interest>();
+ i->wireDecode(payload);
+ if (&payload != &element)
+ {
+ i->getLocalControlHeader().wireDecode(element,
+ false,
+ this->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
+ }
+
+ this->onReceiveInterest(*i);
+ }
+ else if (payload.type() == tlv::Data)
+ {
+ shared_ptr<Data> d = make_shared<Data>();
+ d->wireDecode(payload);
+
+ /// \todo Uncomment and correct the following when we have more
+ /// options in LocalControlHeader that apply for incoming
+ /// Data packets (if ever)
+ // if (&payload != &element)
+ // {
+ //
+ // d->getLocalControlHeader().wireDecode(element,
+ // false,
+ // false);
+ // }
+
+ this->onReceiveData(*d);
+ }
+ else
+ return false;
+
+ return true;
+ }
+ catch (tlv::Error&) {
return false;
-
- if (payload.type() == tlv::Interest)
- {
- shared_ptr<Interest> i = make_shared<Interest>();
- i->wireDecode(payload);
- if (&payload != &element)
- {
- i->getLocalControlHeader().wireDecode(element,
- false,
- this->isLocalControlHeaderEnabled(LOCAL_CONTROL_FEATURE_NEXT_HOP_FACE_ID));
- }
-
- this->onReceiveInterest(*i);
- }
- else if (payload.type() == tlv::Data)
- {
- shared_ptr<Data> d = make_shared<Data>();
- d->wireDecode(payload);
-
- /// \todo Uncomment and correct the following when we have more
- /// options in LocalControlHeader that apply for incoming
- /// Data packets (if ever)
- // if (&payload != &element)
- // {
- //
- // d->getLocalControlHeader().wireDecode(element,
- // false,
- // false);
- // }
-
- this->onReceiveData(*d);
- }
- else
- return false;
-
- return true;
+ }
}
inline bool