mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Fix unbounded memory usage and infinite loop in fgetgrent_r(3).
This commit is contained in:
parent
53f20c5519
commit
6d052efd19
1 changed files with 3 additions and 1 deletions
|
@ -83,6 +83,8 @@ static size_t count_num_members(const char* member_string)
|
|||
result++;
|
||||
while ( *member_string && *member_string != ',' )
|
||||
member_string++;
|
||||
if ( *member_string == ',' )
|
||||
member_string++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -205,7 +207,7 @@ int fgetgrent_r(FILE* restrict fp,
|
|||
|
||||
size_t num_members = count_num_members(member_string);
|
||||
size_t member_list_bytes = (num_members + 1) * sizeof(char*);
|
||||
size_t available_bytes = buf_len < buf_used;
|
||||
size_t available_bytes = buf_len - buf_used;
|
||||
if ( available_bytes < member_list_bytes )
|
||||
goto range_failure;
|
||||
|
||||
|
|
Loading…
Reference in a new issue