suppressed uninitialized memory read in file transfer, also made the TransferDialog more secure

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@2643 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-03-26 22:41:13 +00:00
parent 7c2dd7a7ae
commit d246ff2d7b
3 changed files with 40 additions and 39 deletions

View File

@ -8,7 +8,7 @@
static const time_t UPLOAD_CHUNK_MAPS_TIME = 30 ; // time to ask for a new chunkmap from uploaders in seconds. static const time_t UPLOAD_CHUNK_MAPS_TIME = 30 ; // time to ask for a new chunkmap from uploaders in seconds.
ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string
hash) : mSize(size), hash(hash), file_name(path), fd(NULL),transfer_rate(0),total_size(0) hash) : mSize(size), hash(hash), file_name(path), fd(NULL),transfer_rate(0),total_size(0),req_loc(0)
{ {
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/ RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
clients_chunk_maps.clear(); clients_chunk_maps.clear();

View File

@ -689,7 +689,7 @@ void TransfersDialog::insertTransfers()
FileProgressInfo pinfo ; FileProgressInfo pinfo ;
pinfo.cmap = fcinfo.chunks ; pinfo.cmap = fcinfo.chunks ;
pinfo.type = FileProgressInfo::DOWNLOAD_LINE ; pinfo.type = FileProgressInfo::DOWNLOAD_LINE ;
pinfo.progress = completed*100.0/info.size ; pinfo.progress = (info.size==0)?0:(completed*100.0/info.size) ;
pinfo.nb_chunks = pinfo.cmap._map.empty()?0:fcinfo.chunks.size() ; pinfo.nb_chunks = pinfo.cmap._map.empty()?0:fcinfo.chunks.size() ;
int addedRow = addItem("", fileName, fileHash, fileSize, pinfo, fileDlspeed, sources, status, priority, completed, remaining, downloadtime); int addedRow = addItem("", fileName, fileHash, fileSize, pinfo, fileDlspeed, sources, status, priority, completed, remaining, downloadtime);
@ -834,8 +834,8 @@ void TransfersDialog::insertTransfers()
double dlspeed = pit->tfRate * 1024.0; double dlspeed = pit->tfRate * 1024.0;
qlonglong fileSize = info.size; qlonglong fileSize = info.size;
double completed = info.transfered; qlonglong completed = info.transfered;
double progress = info.transfered * 100.0 / info.size; double progress = (info.size > 0)?(info.transfered * 100.0 / info.size):0.0;
qlonglong remaining = (info.size - info.transfered) / (info.tfRate * 1024.0); qlonglong remaining = (info.size - info.transfered) / (info.tfRate * 1024.0);
// Estimate the completion. We need something more accurate, meaning that we need to // Estimate the completion. We need something more accurate, meaning that we need to
@ -847,49 +847,50 @@ void TransfersDialog::insertTransfers()
++nb_chunks ; ++nb_chunks ;
uint32_t filled_chunks = pinfo.cmap.filledChunks(nb_chunks) ; uint32_t filled_chunks = pinfo.cmap.filledChunks(nb_chunks) ;
pinfo.type = FileProgressInfo::UPLOAD_LINE ;
pinfo.nb_chunks = pinfo.cmap._map.empty()?0:nb_chunks ; pinfo.nb_chunks = pinfo.cmap._map.empty()?0:nb_chunks ;
if(filled_chunks > 1) { if(filled_chunks > 1) {
pinfo.progress = filled_chunks*100.0/nb_chunks ; pinfo.progress = (nb_chunks==0)?0:(filled_chunks*100.0/nb_chunks) ;
completed = std::min(info.size,((uint64_t)filled_chunks)*chunk_size) ; completed = std::min(info.size,((uint64_t)filled_chunks)*chunk_size) ;
} else { }
else
pinfo.progress = progress ; pinfo.progress = progress ;
}
addUploadItem("", fileName, fileHash, fileSize, pinfo, dlspeed, sources, status, completed, remaining); addUploadItem("", fileName, fileHash, fileSize, pinfo, dlspeed, sources, status, completed, remaining);
} }
if (info.peers.size() == 0) { //it has not been added (maybe only turtle tunnels // if (info.peers.size() == 0) { //it has not been added (maybe only turtle tunnels
QString fileHash = QString::fromStdString(info.hash); // QString fileHash = QString::fromStdString(info.hash);
QString fileName = QString::fromUtf8(info.fname.c_str()); // QString fileName = QString::fromUtf8(info.fname.c_str());
QString sources = tr(""); // QString sources = tr("");
//
QString status; // QString status;
switch(info.downloadStatus) // switch(info.downloadStatus)
{ // {
case FT_STATE_FAILED: status = tr("Failed"); break; // case FT_STATE_FAILED: status = tr("Failed"); break;
case FT_STATE_OKAY: status = tr("Okay"); break; // case FT_STATE_OKAY: status = tr("Okay"); break;
case FT_STATE_WAITING: status = tr("Waiting"); break; // case FT_STATE_WAITING: status = tr("Waiting"); break;
case FT_STATE_DOWNLOADING: status = tr("Uploading");break; // case FT_STATE_DOWNLOADING: status = tr("Uploading");break;
case FT_STATE_COMPLETE:status = tr("Complete"); break; // case FT_STATE_COMPLETE:status = tr("Complete"); break;
default: status = tr("Complete"); break; // default: status = tr("Complete"); break;
//
} // }
//
double dlspeed = info.tfRate * 1024.0; // double dlspeed = info.tfRate * 1024.0;
qlonglong fileSize = info.size; // qlonglong fileSize = info.size;
double completed = info.transfered; // double completed = info.transfered;
double progress = info.transfered * 100.0 / info.size; // double progress = info.transfered * 100.0 / info.size;
qlonglong remaining = (info.size - info.transfered) / (info.tfRate * 1024.0); // qlonglong remaining = (info.size - info.transfered) / (info.tfRate * 1024.0);
//
FileProgressInfo pinfo ; // FileProgressInfo pinfo ;
pinfo.progress = progress ; // pinfo.progress = progress ;
pinfo.cmap = CompressedChunkMap() ; // pinfo.cmap = CompressedChunkMap() ;
pinfo.type = FileProgressInfo::DOWNLOAD_LINE ; // pinfo.type = FileProgressInfo::DOWNLOAD_LINE ;
pinfo.nb_chunks = 0 ; // pinfo.nb_chunks = 0 ;
//
addUploadItem("", fileName, fileHash, fileSize, pinfo, dlspeed, sources, status, completed, remaining); // addUploadItem("", fileName, fileHash, fileSize, pinfo, dlspeed, sources, status, completed, remaining);
} // }
} }
} }

View File

@ -218,7 +218,7 @@ void xProgressBar::paint()
else else
{ {
// calculate progress value // calculate progress value
int preWidth = static_cast<int>((rect.width() - 1 - hSpan)*(_pinfo.progress/100)); int preWidth = static_cast<int>((rect.width() - 1 - hSpan)*(_pinfo.progress/100.0f));
int progressWidth = rect.width() - preWidth; int progressWidth = rect.width() - preWidth;
if (progressWidth == rect.width() - hSpan) return; if (progressWidth == rect.width() - hSpan) return;