fix 257560, memory access errors during palmsync sr=mscott

This commit is contained in:
bienvenu%nventure.com 2004-08-31 18:32:18 +00:00
parent bad8733fd8
commit 6c8a47e2ae
2 changed files with 17 additions and 5 deletions

View File

@ -445,10 +445,14 @@ void CPalmSyncImp::CopyCString(LPTSTR *destStr, const nsAFlatCString& srcStr)
if (!destStr)
return;
PRInt32 length = sizeof(char) * (srcStr.Length()+1);
// these strings are defined as wide in the idl, so we need to add up to 3
// bytes of 0 byte padding at the end (if the string is an odd number of
// bytes long, we need one null byte to pad out the last char to a wide char
// and then two more nulls as a wide null terminator.
PRInt32 length = sizeof(char) * (srcStr.Length()+3);
*destStr = (LPTSTR) CoTaskMemAlloc(length);
char *sp = (char *)*destStr;
strncpy(sp, srcStr.get(), length-1);
strncpy(sp, srcStr.get(), length-1); // this will null fill the end of destStr
sp[length-1] = '\0';
}

View File

@ -821,7 +821,11 @@ void nsAbIPCCard::CopyValue(PRBool isUnicode, nsString & attribValue, LPTSTR * r
else {
nsCAutoString cStr;
cStr = NS_LossyConvertUCS2toASCII(attribValue);
length = cStr.Length()+1;
// These strings are defined as wide in the idl, so we need to add up to 3
// bytes of 0 byte padding at the end (if the string is an odd number of
// bytes long, we need one null byte to pad out the last char to a wide char
// and then two more nulls as a wide null terminator.
length = cStr.Length()+3;
char * str = (char *) CoTaskMemAlloc(length);
strncpy(str, cStr.get(), length-1);
str[length-1] = '\0';
@ -912,8 +916,12 @@ void nsAbIPCCard::JoinAddress(PRBool isUnicode, LPTSTR *ptrAddress, nsString &ad
if(!strLength)
return;
// Allocate space for 'strLength' plus one for null and one for "\x0A".
strLength += 2;
// Allocate space for 'strLength' plus three for nulls and one for "\x0A".
// These strings are defined as wide in the idl, so we need to add up to 3
// bytes of 0 byte padding at the end (if the string is an odd number of
// bytes long, we need one null byte to pad out the last char to a wide char
// and then two more nulls as a wide null terminator.
strLength += 4;
if(isUnicode)
{
PRUnichar * uniStr = (PRUnichar *) CoTaskMemAlloc(sizeof(PRUnichar) * (strLength));