From c242fa8095146bfae6fde258ab020360a9123bdb Mon Sep 17 00:00:00 2001 From: Nathan Kinder Date: Thu, 30 Mar 2006 23:13:44 +0000 Subject: 186657 - Implemented locking around passhook data file access --- ldap/synctools/passwordsync/passhand.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'ldap/synctools/passwordsync/passhand.cpp') diff --git a/ldap/synctools/passwordsync/passhand.cpp b/ldap/synctools/passwordsync/passhand.cpp index ddad1977..4cefd58c 100644 --- a/ldap/synctools/passwordsync/passhand.cpp +++ b/ldap/synctools/passwordsync/passhand.cpp @@ -112,6 +112,8 @@ int saveSet(PASS_INFO_LIST* passInfoList, char* filename) outFile.close(); exit: + // We need to unfreeze plainTextStream so memory gets freed by the destructor + plainTextStream.rdbuf()->freeze(false); free(cipherTextBuf); return result; } @@ -119,18 +121,18 @@ exit: int loadSet(PASS_INFO_LIST* passInfoList, char* filename) { int result = 0; - int i; + int i = 0; fstream inFile; PASS_INFO newPair; strstream* plainTextStream; char* cipherTextBuf = NULL; char* plainTextBuf = NULL; - int usernameLen; - int passwordLen; - int plainTextLen; - int cipherTextLen; + int usernameLen = 0; + int passwordLen = 0; + int plainTextLen = 0; + int cipherTextLen = 0; int resultTextLen = 0; - int pairCount; + int pairCount = 0; // Read in cipher text from file inFile.open(filename, ios::in | ios::binary); @@ -164,6 +166,12 @@ int loadSet(PASS_INFO_LIST* passInfoList, char* filename) goto exit; } + // Check to see if plainTextbuf contains anything + if (resultTextLen <= 0) { + result = -1; + goto exit; + } + plainTextStream = new strstream(plainTextBuf, resultTextLen); plainTextStream->read((char*)&pairCount, sizeof(pairCount)); -- cgit