Ver Fonte

2008-02-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Fixed segmentation fault when a DHT message which doesn't have 
'y' key
	received.
	* src/DHTMessageReceiver.cc (receiveMessage)
Tatsuhiro Tsujikawa há 18 anos atrás
pai
commit
1ea9033363
2 ficheiros alterados com 13 adições e 2 exclusões
  1. 6 0
      ChangeLog
  2. 7 2
      src/DHTMessageReceiver.cc

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2008-02-21  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Fixed segmentation fault when a DHT message which doesn't have 'y' key
+	received.
+	* src/DHTMessageReceiver.cc (receiveMessage) 
+
 2008-02-21  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Fixed the bug that a return code is always 0. BUG#1897704

+ 7 - 2
src/DHTMessageReceiver.cc

@@ -78,8 +78,13 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
     const Dictionary* d = dynamic_cast<const Dictionary*>(msgroot.get());
     if(d) {
       const Data* y = dynamic_cast<const Data*>(d->get("y"));
-      if(y->toString() == "r" || y->toString() == "e") {
-	isReply = true;
+      if(y) {
+	if(y->toString() == "r" || y->toString() == "e") {
+	  isReply = true;
+	}
+      } else {
+	_logger->info("Malformed DHT message. Missing 'y' key. From:%s:%u", remoteAddr.c_str(), remotePort);
+	return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort);
       }
     } else {
       _logger->info("Malformed DHT message. This is not a bencoded directory. From:%s:%u", remoteAddr.c_str(), remotePort);