Fix: Sudden exit on bookmarking a new (not saved) file (Bug #2599802)

Safer SecString::overwrite(QString&)

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@261 b624d157-de02-0410-bad0-e51aec6abb33
master
sniperbeamer 15 years ago
parent 77500ca0e9
commit 5e473bedc2
  1. 8
      src/dialogs/AddBookmarkDlg.cpp
  2. 7
      src/lib/SecString.cpp
  3. 20
      src/mainwindow.cpp

@ -29,17 +29,17 @@ AddBookmarkDlg::AddBookmarkDlg(QWidget* parent, QString DefaultFilename, int _It
connect(buttonBox->button(QDialogButtonBox::Ok),SIGNAL(clicked()),this,SLOT(OnButtonOk()));
connect(buttonBox->button(QDialogButtonBox::Cancel),SIGNAL(clicked()),this,SLOT(reject()));
if(ItemID==-1){
createBanner(&BannerPixmap,getPixmap("bookmark_add"),tr("Add Bookmark"),width());
createBanner(&BannerPixmap,getPixmap("bookmark_add"),tr("Add Bookmark"),width());
if(DefaultFilename.isEmpty())
OnButtonBrowse();
QMetaObject::invokeMethod(this, "OnButtonBrowse", Qt::QueuedConnection);
else
Edit_Filename->setText(DefaultFilename);
}
else {
createBanner(&BannerPixmap,getPixmap("bookmark_edit"),tr("Edit Bookmark"),width());
createBanner(&BannerPixmap,getPixmap("bookmark_edit"),tr("Edit Bookmark"),width());
Edit_Title->setText(KpxBookmarks::title(ItemID));
Edit_Title->setText(KpxBookmarks::title(ItemID));
Edit_Filename->setText(KpxBookmarks::path(ItemID));
setWindowTitle(tr("Edit Bookmark"));
}

@ -85,10 +85,9 @@ void SecString::overwrite(unsigned char* str, int strlen){
}
void SecString::overwrite(QString& str){
if(str.length()==0)
return;
overwrite((unsigned char*)str.data(), str.capacity());
for (int i=0; i<str.length(); i++) {
str[i] = '\0';
}
}
void SecString::generateSessionKey(){

@ -451,13 +451,13 @@ bool KeepassMainWindow::openDatabase(QString filename,bool IsAuto){
if (IsLocked)
resetLock();
currentFile = filename;
saveLastFilename(filename);
setWindowTitle(QString("%1[*] - KeePassX").arg(filename));
GroupView->createItems();
EntryView->showGroup(NULL);
setStateFileOpen(true);
setStateFileModified(false);
currentFile = filename;
}
else{
statusbarState = 2;
@ -549,6 +549,7 @@ void KeepassMainWindow::OnFileNewKdb(){
db=db_new;
db->setKey(dlg.password(),dlg.keyFile());
db->generateMasterKey();
currentFile.clear();
setWindowTitle(QString("[%1][*] - KeePassX").arg(tr("new")));
GroupView->db=db;
EntryView->db=db;
@ -610,7 +611,7 @@ void KeepassMainWindow::setStateFileOpen(bool IsOpen){
DetailView->setEnabled(IsOpen);
QuickSearchEdit->setEnabled(IsOpen);
ExtrasShowExpiredEntriesAction->setEnabled(IsOpen);
AddThisAsBookmarkAction->setEnabled(IsOpen);
AddThisAsBookmarkAction->setEnabled(IsOpen && db->file());
FileUnLockWorkspaceAction->setEnabled(IsOpen||IsLocked);
if(!IsOpen){
@ -871,6 +872,7 @@ bool KeepassMainWindow::OnFileSave(){
return OnFileSaveAs();
saveLastFilename(db->file()->fileName());
if(db->save()){
setStateFileOpen(true); // necessary for AddThisAsBookmarkAction
setStateFileModified(false);
if (config->backup() && config->backupDelete() && config->backupDeleteAfter()>0){
IGroupHandle* backupGroup = db->backupGroup();
@ -1369,18 +1371,14 @@ void KeepassMainWindow::OnBookmarkTriggered(QAction* action){
action->setIcon(getIcon("document"));
menuBookmarks->addAction(action);
}
return;
}
if(action==ManageBookmarksAction){
else if(action==ManageBookmarksAction){
ManageBookmarksDlg dlg(this);
dlg.exec();
menuBookmarks->clear();
createBookmarkActions();
return;
}
if(action==AddThisAsBookmarkAction){
else if(action==AddThisAsBookmarkAction){
AddBookmarkDlg dlg(this,db->file()->fileName());
if(dlg.exec()){
int id=dlg.ItemID;
@ -1390,10 +1388,10 @@ void KeepassMainWindow::OnBookmarkTriggered(QAction* action){
action->setIcon(getIcon("document"));
menuBookmarks->addAction(action);
}
return;
}
openDatabase(KpxBookmarks::path(action->data().toInt()));
else {
openDatabase(KpxBookmarks::path(action->data().toInt()));
}
}
void KeepassMainWindow::createBookmarkActions(){