2006-05-29 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

To fix the bug that cause segfaults if a zero-length peer list 
is
	a zero-length list:
	
	* src/TrackerUpdateCommand.cc
	(execute): Added a check to see wether the type of peers is 
Data*.
pull/1/head
Tatsuhiro Tsujikawa 2006-05-29 14:36:25 +00:00
parent 3dcbda0676
commit 7774b6330c
2 changed files with 42 additions and 32 deletions

View File

@ -1,3 +1,11 @@
2006-05-29 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To fix the bug that cause segfaults if a zero-length peer list is
a zero-length list:
* src/TrackerUpdateCommand.cc
(execute): Added a check to see wether the type of peers is Data*.
2006-05-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2006-05-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Release 0.5.0 * Release 0.5.0

View File

@ -125,39 +125,41 @@ bool TrackerUpdateCommand::execute() {
e->torrentMan->incomplete = incomplete->toInt(); e->torrentMan->incomplete = incomplete->toInt();
logger->debug("CUID#%d - Incomplete:%d", logger->debug("CUID#%d - Incomplete:%d",
cuid, e->torrentMan->incomplete); cuid, e->torrentMan->incomplete);
} }
Data* peers = (Data*)response->get("peers"); if(dynamic_cast<const Data*>(response->get("peers"))) {
if(peers != NULL) { Data* peers = (Data*)response->get("peers");
for(int i = 0; i < peers->getLen(); i += 6) { if(peers != NULL && peers->getLen() > 0) {
unsigned int ipaddr1 = (unsigned char)*(peers->getData()+i); for(int i = 0; i < peers->getLen(); i += 6) {
unsigned int ipaddr2 = (unsigned char)*(peers->getData()+i+1); unsigned int ipaddr1 = (unsigned char)*(peers->getData()+i);
unsigned int ipaddr3 = (unsigned char)*(peers->getData()+i+2); unsigned int ipaddr2 = (unsigned char)*(peers->getData()+i+1);
unsigned int ipaddr4 = (unsigned char)*(peers->getData()+i+3); unsigned int ipaddr3 = (unsigned char)*(peers->getData()+i+2);
unsigned int port = ntohs(*(unsigned short int*)(peers->getData()+i+4)); unsigned int ipaddr4 = (unsigned char)*(peers->getData()+i+3);
char ipaddr[16]; unsigned int port = ntohs(*(unsigned short int*)(peers->getData()+i+4));
char ipaddr[16];
snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d",
ipaddr1, ipaddr2, ipaddr3, ipaddr4); snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d",
Peer* peer = new Peer(ipaddr, port, e->torrentMan->pieceLength, ipaddr1, ipaddr2, ipaddr3, ipaddr4);
e->torrentMan->getTotalLength()); Peer* peer = new Peer(ipaddr, port, e->torrentMan->pieceLength,
if(e->torrentMan->addPeer(peer)) { e->torrentMan->getTotalLength());
logger->debug("CUID#%d - Adding peer %s:%d", if(e->torrentMan->addPeer(peer)) {
cuid, peer->ipaddr.c_str(), peer->port); logger->debug("CUID#%d - Adding peer %s:%d",
} else { cuid, peer->ipaddr.c_str(), peer->port);
delete peer; } else {
delete peer;
}
} }
} } else {
} else { logger->info("CUID#%d - No peer list received.", cuid);
logger->info("CUID#%d - No peer list received.", cuid); }
} while(e->torrentMan->isPeerAvailable() &&
while(e->torrentMan->isPeerAvailable() && e->torrentMan->connections < MAX_PEER_UPDATE) {
e->torrentMan->connections < MAX_PEER_UPDATE) { Peer* peer = e->torrentMan->getPeer();
Peer* peer = e->torrentMan->getPeer(); int newCuid = e->torrentMan->getNewCuid();
int newCuid = e->torrentMan->getNewCuid(); peer->cuid = newCuid;
peer->cuid = newCuid; PeerInitiateConnectionCommand* command = new PeerInitiateConnectionCommand(newCuid, peer, e);
PeerInitiateConnectionCommand* command = new PeerInitiateConnectionCommand(newCuid, peer, e); e->commands.push_back(command);
e->commands.push_back(command); logger->debug("CUID#%d - Adding new command CUID#%d", cuid, newCuid);
logger->debug("CUID#%d - Adding new command CUID#%d", cuid, newCuid); }
} }
if(e->torrentMan->req->getTrackerEvent() == Request::STARTED) { if(e->torrentMan->req->getTrackerEvent() == Request::STARTED) {
e->torrentMan->req->setTrackerEvent(Request::AUTO); e->torrentMan->req->setTrackerEvent(Request::AUTO);