Bug 1380078: Fix truncation of buffer size in CFStringRefToUTF8Buffer(); r=spohl

On 64 bit systems CFStringGetMaximumSizeForEncoding() returns a
CFIndex (long) integer which was being converted to an int, which may
not be 64 bit. This has been changed to an int64_t so it will never
truncate.

In addition, in the same function there was a redundant null check on
the return from moz_xmalloc.  This is an infallible memory allocator,
so the check is useless and has been removed.

MozReview-Commit-ID: 7BtBxPmGgQC

--HG--
extra : rebase_source : 9167bf47f839c6e05b7fbff68d525d72c9e2b29e
This commit is contained in:
Maximilian Hunt 2017-08-17 06:26:06 +01:00
Родитель e5f7ecb3d1
Коммит da0908751b
1 изменённых файлов: 1 добавлений и 4 удалений

Просмотреть файл

@ -101,13 +101,10 @@ static char* CFStringRefToUTF8Buffer(CFStringRef cfString)
return PL_strdup(buffer);
}
int bufferLength =
int64_t bufferLength =
::CFStringGetMaximumSizeForEncoding(::CFStringGetLength(cfString),
kCFStringEncodingUTF8) + 1;
char* newBuffer = static_cast<char*>(moz_xmalloc(bufferLength));
if (!newBuffer) {
return nullptr;
}
if (!::CFStringGetCString(cfString, newBuffer, bufferLength,
kCFStringEncodingUTF8)) {