From 4a0f996d42575e55ddce39b8d07cb8a381ab721d Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 25 Sep 2024 03:14:32 +0200 Subject: [PATCH] [winpr,timezone] fix integer narrow --- winpr/libwinpr/timezone/timezone.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/winpr/libwinpr/timezone/timezone.c b/winpr/libwinpr/timezone/timezone.c index 7b8422bf6..05ab5446c 100644 --- a/winpr/libwinpr/timezone/timezone.c +++ b/winpr/libwinpr/timezone/timezone.c @@ -49,24 +49,29 @@ static char* winpr_read_unix_timezone_identifier_from_file(FILE* fp) { const INT CHUNK_SIZE = 32; - INT64 rc = 0; - INT64 read = 0; - INT64 length = CHUNK_SIZE; - char* tzid = NULL; + size_t rc = 0; + size_t read = 0; + size_t length = CHUNK_SIZE; - tzid = (char*)malloc((size_t)length); + char* tzid = malloc(length); if (!tzid) return NULL; do { - rc = fread(tzid + read, 1, length - read - 1, fp); + rc = fread(tzid + read, 1, length - read - 1UL, fp); if (rc > 0) read += rc; - if (read < (length - 1)) + if (read < (length - 1UL)) break; + if (read > length - 1UL) + { + free(tzid); + return NULL; + } + length += CHUNK_SIZE; char* tmp = (char*)realloc(tzid, length); if (!tmp)