From e53f531271455978473e11daaba2a60b2af5be69 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sun, 12 Jul 2015 01:37:48 +0000 Subject: [PATCH] Fixed possible crash in p3GRouter by checking return value of dynamic_cast. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8598 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/grouter/p3grouter.cc | 30 +++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/grouter/p3grouter.cc b/libretroshare/src/grouter/p3grouter.cc index 953412e27..77bcdad05 100644 --- a/libretroshare/src/grouter/p3grouter.cc +++ b/libretroshare/src/grouter/p3grouter.cc @@ -357,17 +357,41 @@ void p3GRouter::handleLowLevelServiceItems() RsItem *item = NULL; while(NULL != (item = recvItem())) - handleLowLevelServiceItem(dynamic_cast(item)) ; + { + RsGRouterTransactionItem *gtitem = dynamic_cast(item); + if (gtitem) + { + handleLowLevelServiceItem(gtitem) ; + } + else + { + delete(item); + } + } } void p3GRouter::handleLowLevelServiceItem(RsGRouterTransactionItem *item) { switch(item->PacketSubType()) { - case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN: handleLowLevelTransactionAckItem(dynamic_cast(item)) ; + case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_ACKN: + { + RsGRouterTransactionAcknItem *trans_ack_item = dynamic_cast(item); + if (trans_ack_item) + { + handleLowLevelTransactionAckItem(trans_ack_item) ; + } break ; - case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK: handleLowLevelTransactionChunkItem(dynamic_cast(item)) ; + } + case RS_PKT_SUBTYPE_GROUTER_TRANSACTION_CHUNK: + { + RsGRouterTransactionChunkItem *chunk_item = dynamic_cast(item); + if (chunk_item) + { + handleLowLevelTransactionChunkItem(chunk_item) ; + } break ; + } default: std::cerr << "p3GRouter::handleIncoming: Unknown packet subtype " << item->PacketSubType() << std::endl ; }