From 5f108132aec8d16132bb72255ca4bd56582cd6b8 Mon Sep 17 00:00:00 2001 From: Derick Payne Date: Mon, 18 Apr 2016 16:36:58 +0200 Subject: [PATCH] Bug in handling wrong passphrase on decryption --- Version.ini | 2 +- crypto/crypto.c | 27 ++++++++++++++------------- minipath/Version.ini | 2 +- minipath/res/MiniPath.exe.manifest | 2 +- minipath/src/VersionEx.h | 2 +- res/Notepad3.exe.manifest | 2 +- src/Edit.c | 10 +++++----- src/VersionEx.h | 2 +- 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Version.ini b/Version.ini index 591b87eac..0f9c86232 100644 --- a/Version.ini +++ b/Version.ini @@ -7,7 +7,7 @@ Language=CPlusPlus Major=auto Minor=auto Maintenance=auto -Build=291 +Build=293 [CSharp] AssemConfig=Rizonesoft.Voice.Win\Properties\AssemblyInfo.cs.conf diff --git a/crypto/crypto.c b/crypto/crypto.c index acaa16be2..fde092b3c 100644 --- a/crypto/crypto.c +++ b/crypto/crypto.c @@ -361,32 +361,33 @@ BOOL ReadAndDecryptFile(HWND hwnd, HANDLE hFile, DWORD size, void** result, DWOR AES_bin_setup(&fileDecode, AES_DIR_DECRYPT, KEY_BYTES * 8, binFileKey); AES_bin_cipherInit(&fileCypher, AES_MODE_CBC, &rawdata[PREAMBLE_SIZE]); // IV is next { // finally, decrypt the actual data - unsigned long nb = 0; + int nbb = 0; + int nbp = 0; if ((readsize - code_offset) > PAD_SLOP) { - nb += AES_blockDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset], readsize - code_offset - PAD_SLOP, rawdata); + nbb = AES_blockDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset], readsize - code_offset - PAD_SLOP, rawdata); } - nb += AES_padDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset + nb], readsize - code_offset - nb, rawdata + nb); - if (nb > 0) { - rawdata[nb] = (char)0; - rawdata[nb + 1] = (char)0; // two zeros in case it's multibyte - *resultlen = (DWORD)nb; - bReadSuccess = 1; - usedEncryption = TRUE; + nbp = AES_padDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset + nbb], readsize - code_offset - nbb, rawdata + nbb); + if (nbp > 0) { + nbb += nbp; + rawdata[nbb] = (char)0; + rawdata[nbb + 1] = (char)0; // two zeros in case it's multi-byte + *resultlen = (DWORD)nbb; + bReadSuccess = TRUE; } else { - *resultlen = 0; MsgBox(MBWARN, IDS_PASS_FAILURE); - bReadSuccess = -1; - usedEncryption = FALSE; + *resultlen = 0; + bReadSuccess = FALSE; } } + usedEncryption = TRUE; } else { // simulate read failure MsgBox(MBWARN, IDS_NOPASS); *resultlen = 0; - bReadSuccess = -1; + bReadSuccess = FALSE; usedEncryption = FALSE; } } diff --git a/minipath/Version.ini b/minipath/Version.ini index 1a0cd42a7..90b899f88 100644 --- a/minipath/Version.ini +++ b/minipath/Version.ini @@ -1,4 +1,4 @@ [Version] -Build=60 +Build=62 VersionHeader=src\VersionEx.h ManifestConfig=res\MiniPath.exe.manifest.conf diff --git a/minipath/res/MiniPath.exe.manifest b/minipath/res/MiniPath.exe.manifest index 293636e66..1a60b2588 100644 --- a/minipath/res/MiniPath.exe.manifest +++ b/minipath/res/MiniPath.exe.manifest @@ -3,7 +3,7 @@ metapath diff --git a/minipath/src/VersionEx.h b/minipath/src/VersionEx.h index 3dfd88035..07d227aef 100644 --- a/minipath/src/VersionEx.h +++ b/minipath/src/VersionEx.h @@ -1,4 +1,4 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 0 #define VERSION_REV 6 -#define VERSION_BUILD 60 +#define VERSION_BUILD 62 diff --git a/res/Notepad3.exe.manifest b/res/Notepad3.exe.manifest index be01b5258..c3fb8ae52 100644 --- a/res/Notepad3.exe.manifest +++ b/res/Notepad3.exe.manifest @@ -3,7 +3,7 @@ Notepad3 diff --git a/src/Edit.c b/src/Edit.c index 17d388d8c..90172ffbe 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -1775,7 +1775,7 @@ void EditTitleCase(HWND hwnd) { if (IsCharLowerW(pszTextW[i])) { - pszTextW[i] = LOWORD(CharUpperW((LPWSTR)MAKELONG(pszTextW[i],0))); + pszTextW[i] = LOWORD(CharUpperW((LPWSTR)(SIZE_T)MAKELONG(pszTextW[i],0))); bChanged = TRUE; } } @@ -1783,7 +1783,7 @@ void EditTitleCase(HWND hwnd) { if (IsCharUpperW(pszTextW[i])) { - pszTextW[i] = LOWORD(CharLowerW((LPWSTR)MAKELONG(pszTextW[i],0))); + pszTextW[i] = LOWORD(CharLowerW((LPWSTR)(SIZE_T)MAKELONG(pszTextW[i],0))); bChanged = TRUE; } } @@ -2212,7 +2212,7 @@ void EditHex2Char(HWND hwnd) { bTrySelExpand = TRUE; } - if (sscanf(ch,"%x",&i) == 1) { + if (sscanf_s(ch,"%x",&i) == 1) { int cch; if (i == 0) { ch[0] = 0; @@ -2264,7 +2264,7 @@ void EditModifyNumber(HWND hwnd,BOOL bIncrease) { if (StrChrIA(chNumber,'-')) return; - if (!StrChrIA(chNumber,'x') && sscanf(chNumber,"%d",&iNumber) == 1) { + if (!StrChrIA(chNumber, 'x') && sscanf_s(chNumber, "%d", &iNumber) == 1) { iWidth = lstrlenA(chNumber); if (iNumber >= 0) { if (bIncrease && iNumber < INT_MAX) @@ -7103,7 +7103,7 @@ BOOL FileVars_ParseInt(char* pszData,char* pszName,int* piValue) { *pvEnd = 0; StrTrimA(tch," \t:=\"'"); - itok = sscanf(tch,"%i",piValue); + itok = sscanf_s(tch,"%i",piValue); if (itok == 1) return(TRUE); diff --git a/src/VersionEx.h b/src/VersionEx.h index bfed63945..87ad6fc5b 100644 --- a/src/VersionEx.h +++ b/src/VersionEx.h @@ -1,4 +1,4 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_REV 9 -#define VERSION_BUILD 291 +#define VERSION_BUILD 293