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:
parent
1905524442
commit
43dc14f94b
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user