Merge pull request #2743 from csoler/v0.6-BugFixing_30

fixed uninitialized memory read in FileDetail struct causing weird dates in search dialog
This commit is contained in:
csoler 2023-06-13 11:12:39 +02:00 committed by GitHub
commit 7fb0fb49f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 17 deletions

View File

@ -86,6 +86,18 @@ const int SearchDialog::FILETYPE_IDX_DIRECTORY = 8;
QMap<int, QString> * SearchDialog::FileTypeExtensionMap = new QMap<int, QString>();
bool SearchDialog::initialised = false;
struct SearchDialog::FileDetail
{
public:
RsPeerId id;
std::string name;
RsFileHash hash;
std::string path;
uint64_t size;
uint32_t mtime;
uint32_t rank;
};
/** Constructor */
SearchDialog::SearchDialog(QWidget *parent)
: MainPage(parent),
@ -265,6 +277,8 @@ void SearchDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
f.hash = fe->mResults[i].fHash;
f.name = fe->mResults[i].fName;
f.size = fe->mResults[i].fSize;
f.mtime = 0; // zero what's not available, otherwise we'll get some random values displayed.
f.rank = 0;
updateFiles(fe->mRequestId,f);
}
@ -966,7 +980,7 @@ void SearchDialog::searchKeywords(const QString& keywords)
}
}
void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
void SearchDialog::updateFiles(qulonglong search_id,const FileDetail& file)
{
searchResultsQueue.push_back(std::pair<qulonglong,FileDetail>(search_id,file)) ;
@ -1320,8 +1334,8 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s
item->setText(SR_SIZE_COL, QString::number(file.size));
item->setData(SR_SIZE_COL, ROLE_SORT, (qulonglong) file.size);
item->setText(SR_AGE_COL, QString::number(file.age));
item->setData(SR_AGE_COL, ROLE_SORT, file.age);
item->setText(SR_AGE_COL, QString::number(file.mtime));
item->setData(SR_AGE_COL, ROLE_SORT, file.mtime);
item->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
int friendSource = 0;
int anonymousSource = 0;
@ -1396,21 +1410,21 @@ void SearchDialog::resultsToTree(const QString& txt,qulonglong searchId, const s
std::list<DirDetails>::const_iterator it;
for(it = results.begin(); it != results.end(); ++it)
if (it->type == DIR_TYPE_FILE) {
if (it->type == DIR_TYPE_FILE)
{
FileDetail fd;
fd.id = it->id;
fd.name = it->name;
fd.hash = it->hash;
fd.path = it->path;
fd.size = it->size;
fd.age = it->mtime;
fd.mtime= it->mtime;
fd.rank = 0;
insertFile(searchId,fd, FRIEND_SEARCH);
} else if (it->type == DIR_TYPE_DIR) {
// insertDirectory(txt, searchId, *it, NULL);
}
else if (it->type == DIR_TYPE_DIR)
insertDirectory(txt, searchId, *it);
}
ui.searchResultWidget->setSortingEnabled(true);
}

View File

@ -43,6 +43,7 @@ class SearchDialog : public MainPage
Q_PROPERTY(QColor textColorLowSources READ textColorLowSources WRITE setTextColorLowSources)
Q_PROPERTY(QColor textColorHighSources READ textColorHighSources WRITE setTextColorHighSources)
struct FileDetail; // useful structure to store search results.
public:
/** Default Constructor */
SearchDialog(QWidget *parent = 0);
@ -63,8 +64,7 @@ public:
void setTextColorLowSources(QColor color) { mTextColorLowSources = color; }
void setTextColorHighSources(QColor color) { mTextColorHighSources = color; }
public slots:
void updateFiles(qulonglong request_id,FileDetail file) ;
void updateFiles(qulonglong request_id, const FileDetail& file) ;
private slots:

View File

@ -91,7 +91,8 @@ class RSHumanReadableAgeDelegate: public RSHumanReadableDelegate
QStyleOptionViewItem opt(option) ;
setPainterOptions(painter,opt,index) ;
painter->drawText(opt.rect, Qt::AlignCenter, misc::timeRelativeToNow(index.data().toLongLong())) ;
if(index.data().toLongLong() > 0) // no date is present.
painter->drawText(opt.rect, Qt::AlignCenter, misc::timeRelativeToNow(index.data().toLongLong())) ;
}
};

View File

@ -117,7 +117,6 @@ class NotifyQt: public QObject, public NotifyClient
void chatStatusChanged(const ChatId&,const QString&) const ;
void chatCleared(const ChatId&) const ;
void peerHasNewCustomStateString(const QString& /* peer_id */, const QString& /* status_string */) const ;
void gotTurtleSearchResult(qulonglong search_id,FileDetail file) const ;
void peerHasNewAvatar(const QString& peer_id) const ;
void ownAvatarChanged() const ;
void ownStatusMessageChanged() const ;

View File

@ -46,6 +46,8 @@ TransferPage::TransferPage(QWidget * parent, Qt::WindowFlags flags)
ui._max_tr_up_per_sec_SB->setMinimum(max_tr_low);
ui._max_tr_up_per_sec_SB->setMaximum(max_tr_high);
whileBlocking(ui._trustFriendNodesWithBannedFiles_CB)->setChecked(rsFiles->trustFriendNodesWithBannedFiles());
QObject::connect(ui._queueSize_SB,SIGNAL(valueChanged(int)),this,SLOT(updateQueueSize(int))) ;
QObject::connect(ui._max_up_SB,SIGNAL(valueChanged(int)),this,SLOT(updateMaxUploadSlots(int))) ;
QObject::connect(ui._defaultStrategy_CB,SIGNAL(activated(int)),this,SLOT(updateDefaultStrategy(int))) ;
@ -53,6 +55,7 @@ TransferPage::TransferPage(QWidget * parent, Qt::WindowFlags flags)
QObject::connect(ui._diskSpaceLimit_SB,SIGNAL(valueChanged(int)),this,SLOT(updateDiskSizeLimit(int))) ;
QObject::connect(ui._max_tr_up_per_sec_SB, SIGNAL( valueChanged( int ) ), this, SLOT( updateMaxTRUpRate(int) ) );
QObject::connect(ui._filePermDirectDL_CB,SIGNAL(activated(int)),this,SLOT(updateFilePermDirectDL(int)));
QObject::connect(ui._trustFriendNodesWithBannedFiles_CB,SIGNAL(toggled(bool)),this,SLOT(toggleTrustFriendNodesWithBannedFiles(bool))) ;
QObject::connect(ui.incomingButton, SIGNAL(clicked( bool ) ), this , SLOT( setIncomingDirectory() ) );
QObject::connect(ui.autoDLColl_CB, SIGNAL(toggled(bool)), this, SLOT(updateAutoDLColl()));
@ -94,7 +97,10 @@ void TransferPage::updateIgnoreLists()
std::cerr << " suffixes: " ; for(auto it(ls.begin());it!=ls.end();++it) std::cerr << "\"" << *it << "\" " ; std::cerr << std::endl;
#endif
}
void TransferPage::toggleTrustFriendNodesWithBannedFiles(bool b)
{
rsFiles->setTrustFriendNodesWithBannedFiles(b);
}
void TransferPage::updateMaxTRUpRate(int b)
{
rsTurtle->setMaxTRForwardRate(b) ;

View File

@ -58,7 +58,8 @@ class TransferPage: public ConfigPage
void updateAutoDLColl();
void setPartialsDirectory();
void toggleAutoCheckDirectories(bool);
void updateFontSize();
void toggleTrustFriendNodesWithBannedFiles(bool);
void updateFontSize();
void updateAutoCheckDirectories() ;
void updateAutoScanDirectoriesPeriod() ;

View File

@ -547,7 +547,7 @@ p, li { white-space: pre-wrap; }
</layout>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="_trustFriendNodesWithBannedFiles_CB">
<property name="text">
<string>Trust friend nodes with banned files</string>
</property>

View File

@ -536,11 +536,9 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
// avoid clashes between infos from threads.
//
qRegisterMetaType<FileDetail>("FileDetail") ;
qRegisterMetaType<RsPeerId>("RsPeerId") ;
std::cerr << "connecting signals and slots" << std::endl ;
// QObject::connect(notify,SIGNAL(gotTurtleSearchResult(qulonglong,FileDetail)),w->transfersDialog->searchDialog ,SLOT(updateFiles(qulonglong,FileDetail))) ;
QObject::connect(notify,SIGNAL(deferredSignatureHandlingRequested()),notify,SLOT(handleSignatureEvent()),Qt::QueuedConnection) ;
QObject::connect(notify,SIGNAL(chatLobbyTimeShift(int)),notify,SLOT(handleChatLobbyTimeShift(int)),Qt::QueuedConnection) ;
QObject::connect(notify,SIGNAL(diskFull(int,int)) ,w ,SLOT(displayDiskSpaceWarning(int,int))) ;