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:
@@ -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 ); }
|
||||||
|
|||||||
Reference in New Issue
Block a user