Author: nkinder
Update of /cvs/dirsec/winsync/passwordsync
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv12256/passwordsync
Modified Files:
passhand.cpp
Log Message:
186765 - Fixed memory leaks in passsync service
Index: passhand.cpp
===================================================================
RCS file: /cvs/dirsec/winsync/passwordsync/passhand.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- passhand.cpp 19 Apr 2005 22:07:43 -0000 1.7
+++ passhand.cpp 18 Mar 2006 00:36:33 -0000 1.8
@@ -62,7 +62,7 @@
fstream outFile;
PASS_INFO_LIST_ITERATOR currentPair;
strstream plainTextStream;
- char* cipherTextBuf;
+ char* cipherTextBuf = NULL;
int usernameLen;
int passwordLen;
int plainTextLen;
@@ -90,7 +90,10 @@
// cipherTextBuf length must be at least plainTextLen + 8
cipherTextLen = plainTextLen + 8;
- cipherTextBuf = (char*)malloc(cipherTextLen);
+ if ((cipherTextBuf = (char*)malloc(cipherTextLen)) == NULL) {
+ result = -1;
+ goto exit;
+ }
if(encrypt(plainTextStream.str(), plainTextLen, cipherTextBuf, cipherTextLen,
&resultTextLen) != 0)
{
@@ -109,6 +112,7 @@
outFile.close();
exit:
+ free(cipherTextBuf);
return result;
}
@@ -119,8 +123,8 @@
fstream inFile;
PASS_INFO newPair;
strstream* plainTextStream;
- char* cipherTextBuf;
- char* plainTextBuf;
+ char* cipherTextBuf = NULL;
+ char* plainTextBuf = NULL;
int usernameLen;
int passwordLen;
int plainTextLen;
@@ -145,6 +149,12 @@
cipherTextBuf = (char*)malloc(cipherTextLen);
plainTextBuf = (char*)malloc(plainTextLen);
+ if ((cipherTextBuf == NULL) || (plainTextBuf == NULL)) {
+ result = -1;
+ inFile.close();
+ goto exit;
+ }
+
inFile.read(cipherTextBuf, cipherTextLen);
inFile.close();
@@ -183,6 +193,8 @@
delete plainTextStream;
exit:
+ free(cipherTextBuf);
+ free(plainTextBuf);
return result;
}
@@ -205,7 +217,6 @@
PK11Context* EncContext = NULL;
unsigned char gKey[] = KEY;
unsigned char gIV[] = IV;
- PK11SymKey* key = NULL;
SECItem keyItem;
SECItem ivItem;
CK_MECHANISM_TYPE cipherMech = CKM_DES_CBC_PAD;
@@ -234,6 +245,7 @@
SymKey = PK11_ImportSymKey(slot, cipherMech, PK11_OriginUnwrap, CKA_ENCRYPT,
&keyItem, NULL);
if(SymKey == NULL)
{
+ PK11_FreeSlot(slot);
result = PR_GetError();
goto exit;
}
@@ -247,6 +259,7 @@
if(SymKey != NULL)
{
PK11_FreeSymKey(SymKey);
+ PK11_FreeSlot(slot);
}
result = PR_GetError();
goto exit;
@@ -266,6 +279,7 @@
// Clean up
PK11_DestroyContext(EncContext, PR_TRUE);
PK11_FreeSymKey(SymKey);
+ PK11_FreeSlot(slot);
SECITEM_FreeItem(SecParam, PR_TRUE);
if((rv2 != SECSuccess) || (rv2 != SECSuccess))
@@ -288,7 +302,6 @@
PK11Context* EncContext = NULL;
unsigned char gKey[] = KEY;
unsigned char gIV[] = IV;
- PK11SymKey* key = NULL;
SECItem keyItem;
SECItem ivItem;
CK_MECHANISM_TYPE cipherMech = CKM_DES_CBC_PAD;
@@ -317,6 +330,7 @@
SymKey = PK11_ImportSymKey(slot, cipherMech, PK11_OriginUnwrap, CKA_ENCRYPT,
&keyItem, NULL);
if(SymKey == NULL)
{
+ PK11_FreeSlot(slot);
result = PR_GetError();
goto exit;
}
@@ -330,6 +344,7 @@
if(SymKey != NULL)
{
PK11_FreeSymKey(SymKey);
+ PK11_FreeSlot(slot);
}
result = PR_GetError();
goto exit;
@@ -349,6 +364,7 @@
// Clean up
PK11_DestroyContext(EncContext, PR_TRUE);
PK11_FreeSymKey(SymKey);
+ PK11_FreeSlot(slot);
SECITEM_FreeItem(SecParam, PR_TRUE);
if((rv2 != SECSuccess) || (rv2 != SECSuccess))