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