Fix possible out of bound write in winpr_read_unix_timezone_identifier_from_file (#8207)

If the timezone can not be read from the file (read 0 bytes) then memory
at a random position (buffer[-1] = '\0') will be set to zero.
This commit is contained in:
akallabeth 2022-09-14 16:26:24 +02:00 committed by GitHub
parent 1905524442
commit 43dc14f94b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,7 +64,8 @@ static char* winpr_read_unix_timezone_identifier_from_file(FILE* fp)
do
{
rc = fread(tzid + read, 1, length - read - 1, fp);
read += rc;
if (rc > 0)
read += rc;
if (read < (length - 1))
break;
@ -87,8 +88,11 @@ static char* winpr_read_unix_timezone_identifier_from_file(FILE* fp)
}
tzid[read] = '\0';
if (tzid[read - 1] == '\n')
tzid[read - 1] = '\0';
if (read > 0)
{
if (tzid[read - 1] == '\n')
tzid[read - 1] = '\0';
}
return tzid;
}