Fixed possible crash in ftServer::receiveTurtleData by checking return value of dynamic_cast.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8595 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2015-07-12 01:16:16 +00:00
parent 3abec3363d
commit 865a45f294

View File

@ -1160,34 +1160,42 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
case RS_TURTLE_SUBTYPE_FILE_REQUEST: case RS_TURTLE_SUBTYPE_FILE_REQUEST:
{ {
RsTurtleFileRequestItem *item = dynamic_cast<RsTurtleFileRequestItem *>(i) ; RsTurtleFileRequestItem *item = dynamic_cast<RsTurtleFileRequestItem *>(i) ;
if (item)
{
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "ftServer::receiveTurtleData(): received file data request for " << hash << " from peer " << virtual_peer_id << std::endl; std::cerr << "ftServer::receiveTurtleData(): received file data request for " << hash << " from peer " << virtual_peer_id << std::endl;
#endif #endif
getMultiplexer()->recvDataRequest(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size) ; getMultiplexer()->recvDataRequest(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size) ;
}
} }
break ; break ;
case RS_TURTLE_SUBTYPE_FILE_DATA : case RS_TURTLE_SUBTYPE_FILE_DATA :
{ {
RsTurtleFileDataItem *item = dynamic_cast<RsTurtleFileDataItem *>(i) ; RsTurtleFileDataItem *item = dynamic_cast<RsTurtleFileDataItem *>(i) ;
if (item)
{
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "ftServer::receiveTurtleData(): received file data for " << hash << " from peer " << virtual_peer_id << std::endl; std::cerr << "ftServer::receiveTurtleData(): received file data for " << hash << " from peer " << virtual_peer_id << std::endl;
#endif #endif
getMultiplexer()->recvData(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size,item->chunk_data) ; getMultiplexer()->recvData(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size,item->chunk_data) ;
item->chunk_data = NULL ; // this prevents deletion in the destructor of RsFileDataItem, because data will be deleted
// down _ft_server->getMultiplexer()->recvData()...in ftTransferModule::recvFileData
item->chunk_data = NULL ; // this prevents deletion in the destructor of RsFileDataItem, because data will be deleted
// down _ft_server->getMultiplexer()->recvData()...in ftTransferModule::recvFileData
}
} }
break ; break ;
case RS_TURTLE_SUBTYPE_FILE_MAP : case RS_TURTLE_SUBTYPE_FILE_MAP :
{ {
RsTurtleFileMapItem *item = dynamic_cast<RsTurtleFileMapItem *>(i) ; RsTurtleFileMapItem *item = dynamic_cast<RsTurtleFileMapItem *>(i) ;
if (item)
{
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "ftServer::receiveTurtleData(): received chunk map for hash " << hash << " from peer " << virtual_peer_id << std::endl; std::cerr << "ftServer::receiveTurtleData(): received chunk map for hash " << hash << " from peer " << virtual_peer_id << std::endl;
#endif #endif
getMultiplexer()->recvChunkMap(virtual_peer_id,hash,item->compressed_map,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; getMultiplexer()->recvChunkMap(virtual_peer_id,hash,item->compressed_map,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ;
}
} }
break ; break ;
@ -1204,20 +1212,26 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i,
case RS_TURTLE_SUBTYPE_CHUNK_CRC : case RS_TURTLE_SUBTYPE_CHUNK_CRC :
{ {
RsTurtleChunkCrcItem *item = dynamic_cast<RsTurtleChunkCrcItem *>(i) ; RsTurtleChunkCrcItem *item = dynamic_cast<RsTurtleChunkCrcItem *>(i) ;
if (item)
{
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "ftServer::receiveTurtleData(): received single chunk CRC for hash " << hash << " from peer " << virtual_peer_id << std::endl; std::cerr << "ftServer::receiveTurtleData(): received single chunk CRC for hash " << hash << " from peer " << virtual_peer_id << std::endl;
#endif #endif
getMultiplexer()->recvSingleChunkCRC(virtual_peer_id,hash,item->chunk_number,item->check_sum) ; getMultiplexer()->recvSingleChunkCRC(virtual_peer_id,hash,item->chunk_number,item->check_sum) ;
}
} }
break ; break ;
case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST: case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST:
{ {
RsTurtleChunkCrcRequestItem *item = dynamic_cast<RsTurtleChunkCrcRequestItem *>(i) ; RsTurtleChunkCrcRequestItem *item = dynamic_cast<RsTurtleChunkCrcRequestItem *>(i) ;
if (item)
{
#ifdef SERVER_DEBUG #ifdef SERVER_DEBUG
std::cerr << "ftServer::receiveTurtleData(): received single chunk CRC request for hash " << hash << " from peer " << virtual_peer_id << std::endl; std::cerr << "ftServer::receiveTurtleData(): received single chunk CRC request for hash " << hash << " from peer " << virtual_peer_id << std::endl;
#endif #endif
getMultiplexer()->recvSingleChunkCRCRequest(virtual_peer_id,hash,item->chunk_number) ; getMultiplexer()->recvSingleChunkCRCRequest(virtual_peer_id,hash,item->chunk_number) ;
}
} }
break ; break ;
default: default: