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 16 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::Ok),SIGNAL(clicked()),this,SLOT(OnButtonOk()));
connect(buttonBox->button(QDialogButtonBox::Cancel),SIGNAL(clicked()),this,SLOT(reject())); connect(buttonBox->button(QDialogButtonBox::Cancel),SIGNAL(clicked()),this,SLOT(reject()));
if(ItemID==-1){ if(ItemID==-1){
createBanner(&BannerPixmap,getPixmap("bookmark_add"),tr("Add Bookmark"),width()); createBanner(&BannerPixmap,getPixmap("bookmark_add"),tr("Add Bookmark"),width());
if(DefaultFilename.isEmpty()) if(DefaultFilename.isEmpty())
OnButtonBrowse(); QMetaObject::invokeMethod(this, "OnButtonBrowse", Qt::QueuedConnection);
else else
Edit_Filename->setText(DefaultFilename); Edit_Filename->setText(DefaultFilename);
} }
else { 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)); Edit_Filename->setText(KpxBookmarks::path(ItemID));
setWindowTitle(tr("Edit Bookmark")); setWindowTitle(tr("Edit Bookmark"));
} }

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

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