face: drop WebSocket message if the size is larger than maximum NDN packet size
Change-Id: I8e2bd81bbd0d4ba3598ab7c16a3125189b38ca4f
refs: #2081
diff --git a/daemon/face/websocket-face.cpp b/daemon/face/websocket-face.cpp
index 5b295b3..5c999a1 100644
--- a/daemon/face/websocket-face.cpp
+++ b/daemon/face/websocket-face.cpp
@@ -99,7 +99,13 @@
WebSocketFace::handleReceive(const std::string& msg)
{
// Copy message into Face internal buffer
- BOOST_ASSERT(msg.size() <= MAX_NDN_PACKET_SIZE);
+ if (msg.size() > MAX_NDN_PACKET_SIZE)
+ {
+ NFD_LOG_WARN("[id:" << this->getId()
+ << "] Received WebSocket message size ["
+ << msg.size() << "] is too big");
+ return;
+ }
this->getMutableCounters().getNInBytes() += msg.size();
@@ -109,9 +115,9 @@
isOk = Block::fromBuffer(reinterpret_cast<const uint8_t*>(msg.c_str()), msg.size(), element);
if (!isOk)
{
- NFD_LOG_TRACE("[id:" << this->getId()
- << "] Received invalid NDN packet of length ["
- << msg.size() << "]");
+ NFD_LOG_WARN("[id:" << this->getId()
+ << "] Received invalid NDN packet of length ["
+ << msg.size() << "]");
return;
}
diff --git a/tests/daemon/face/websocket.cpp b/tests/daemon/face/websocket.cpp
index 65f0124..fa93b6a 100644
--- a/tests/daemon/face/websocket.cpp
+++ b/tests/daemon/face/websocket.cpp
@@ -246,9 +246,14 @@
shared_ptr<Interest> interest2 = makeInterest("ndn:/QWiIMfj5sL");
shared_ptr<Data> data2 = makeData("ndn:/XNBV796f");
+ std::string bigName("ndn:/");
+ bigName.append(9000, 'a');
+ shared_ptr<Interest> bigInterest = makeInterest(bigName);
+
client1_sendInterest(*interest1);
client1_sendInterest(*interest1);
client1_sendInterest(*interest1);
+ client1_sendInterest(*bigInterest); // This one should be ignored by face1
face1->sendData (*data1);
face1->sendInterest (*interest2);
client1_sendData (*data2);