Fix memory leak and possible buffer overflow. CFStringGetMaximumSizeForEncoding() doesn't mention anything about NULL terminators so add one to protect against that.

This commit is contained in:
Steve Checkoway
2006-09-17 05:14:20 +00:00
parent a5ecf51f8a
commit 941dac27b3
+5 -7
View File
@@ -106,15 +106,13 @@ static bool ConvertFromCP( RString &sText, int iCodePage )
return false; return false;
const size_t size = CFStringGetMaximumSizeForEncoding( CFStringGetLength(old), kCFStringEncodingUTF8 ); const size_t size = CFStringGetMaximumSizeForEncoding( CFStringGetLength(old), kCFStringEncodingUTF8 );
char *buf = new char[size]; char *buf = new char[size+1];
if( !CFStringGetCString(old, buf, size, kCFStringEncodingUTF8) ) buf[0] = '\0';
{ bool result = CFStringGetCString( old, buf, size, kCFStringEncodingUTF8 );
delete[] buf;
return false;
}
sText = buf; sText = buf;
delete[] buf; delete[] buf;
return true; CFRelease( old );
return result;
} }
static bool AttemptEnglishConversion( RString &sText ) { return ConvertFromCP( sText, 1252 ); } static bool AttemptEnglishConversion( RString &sText ) { return ConvertFromCP( sText, 1252 ); }