[winpr,timezone] fix integer narrow

This commit is contained in:
akallabeth 2024-09-25 03:14:32 +02:00
parent 57f69ad77d
commit 4a0f996d42
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5

View File

@ -49,24 +49,29 @@
static char* winpr_read_unix_timezone_identifier_from_file(FILE* fp) static char* winpr_read_unix_timezone_identifier_from_file(FILE* fp)
{ {
const INT CHUNK_SIZE = 32; const INT CHUNK_SIZE = 32;
INT64 rc = 0; size_t rc = 0;
INT64 read = 0; size_t read = 0;
INT64 length = CHUNK_SIZE; size_t length = CHUNK_SIZE;
char* tzid = NULL;
tzid = (char*)malloc((size_t)length); char* tzid = malloc(length);
if (!tzid) if (!tzid)
return NULL; return NULL;
do do
{ {
rc = fread(tzid + read, 1, length - read - 1, fp); rc = fread(tzid + read, 1, length - read - 1UL, fp);
if (rc > 0) if (rc > 0)
read += rc; read += rc;
if (read < (length - 1)) if (read < (length - 1UL))
break; break;
if (read > length - 1UL)
{
free(tzid);
return NULL;
}
length += CHUNK_SIZE; length += CHUNK_SIZE;
char* tmp = (char*)realloc(tzid, length); char* tmp = (char*)realloc(tzid, length);
if (!tmp) if (!tmp)