From 7c117cdab2b376008c8fae8eb5671d7ee14a8256 Mon Sep 17 00:00:00 2001 From: tarek_saidi Date: Tue, 11 Mar 2008 22:08:26 +0000 Subject: [PATCH] fixed bug #1648616 git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@180 b624d157-de02-0410-bad0-e51aec6abb33 --- changelog | 1 + src/Kdb3Database.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/changelog b/changelog index 5e7f26b..5b469f2 100644 --- a/changelog +++ b/changelog @@ -10,6 +10,7 @@ - fixed potential compilation problem in AES implementation (Bug #1905810) - fixed crash when re-arranging groups (Bug #1754998) - fixed size problems of some dialogs +- files are not longer truncated when saving fails (Bug #1648616) --------------- 0.3.0a diff --git a/src/Kdb3Database.cpp b/src/Kdb3Database.cpp index 00c5398..f7503bf 100644 --- a/src/Kdb3Database.cpp +++ b/src/Kdb3Database.cpp @@ -1101,6 +1101,7 @@ bool Kdb3Database::save(){ quint8 FinalRandomSeed[16]; quint8 ContentsHash[32]; quint8 EncryptionIV[16]; + if(!(File->openMode() & QIODevice::WriteOnly)){ File->close(); } @@ -1239,9 +1240,15 @@ bool Kdb3Database::save(){ return false; } - File->resize(0); //truncate + if(!File->resize(EncryptedPartSize+DB_HEADER_SIZE)){ + delete [] buffer; + error=decodeFileError(File->error()); + return false; + } + File->seek(0); if(File->write(buffer,EncryptedPartSize+DB_HEADER_SIZE)!=EncryptedPartSize+DB_HEADER_SIZE){ delete [] buffer; + error=decodeFileError(File->error()); return false; } File->flush();