diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-12-13 15:55:09 -0500 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-12-14 07:25:36 -0500 |
commit | e305b32d9ac235933aeba775ab249812552d9334 (patch) | |
tree | d1bea958a0cda26a7eb8678d01ff8a6cd3807abc /Userland/Libraries/LibCore/Group.cpp | |
parent | d09266237d07924f382fb193159e0b5504b18135 (diff) | |
download | serenity-e305b32d9ac235933aeba775ab249812552d9334.zip |
LibCore: Protect Core::Group against null group::gr_mem members
Serenity's implementation does not set this pointer to anything, so we
should not assume it was set.
Diffstat (limited to 'Userland/Libraries/LibCore/Group.cpp')
-rw-r--r-- | Userland/Libraries/LibCore/Group.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Userland/Libraries/LibCore/Group.cpp b/Userland/Libraries/LibCore/Group.cpp index 6dc3c172a3..66df15e2d6 100644 --- a/Userland/Libraries/LibCore/Group.cpp +++ b/Userland/Libraries/LibCore/Group.cpp @@ -33,8 +33,10 @@ ErrorOr<DeprecatedString> Group::generate_group_file() const builder.appendff("{}:x:{}:{}\n", m_name, m_id, DeprecatedString::join(',', m_members)); else { Vector<DeprecatedString> members; - for (size_t i = 0; group->gr_mem[i]; ++i) - members.append(group->gr_mem[i]); + if (group->gr_mem) { + for (size_t i = 0; group->gr_mem[i]; ++i) + members.append(group->gr_mem[i]); + } builder.appendff("{}:x:{}:{}\n", group->gr_name, group->gr_gid, DeprecatedString::join(',', members)); } @@ -129,10 +131,12 @@ ErrorOr<Vector<Group>> Group::all() break; Vector<DeprecatedString> members; - for (size_t i = 0; group->gr_mem[i]; ++i) - members.append(group->gr_mem[i]); + if (group->gr_mem) { + for (size_t i = 0; group->gr_mem[i]; ++i) + members.append(group->gr_mem[i]); + } - groups.append({ group->gr_name, group->gr_gid, members }); + groups.append({ group->gr_name, group->gr_gid, move(members) }); } return groups; |