mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:28:11 +00:00
FileManager: Fix crash when file properties has unnamed UID or GID
It's perfectly valid for a file to be owned by a UID or GID with no corresponding entry in /etc/passwd or /etc/group respectively. Fixes #1988.
This commit is contained in:
parent
9f32d71782
commit
85fd0d2187
1 changed files with 17 additions and 6 deletions
|
@ -94,9 +94,20 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
|
|||
return;
|
||||
}
|
||||
|
||||
struct passwd* user_pw = getpwuid(st.st_uid);
|
||||
struct group* group_gr = getgrgid(st.st_gid);
|
||||
ASSERT(user_pw && group_gr);
|
||||
String owner_name;
|
||||
String group_name;
|
||||
|
||||
if (auto* pw = getpwuid(st.st_uid)) {
|
||||
owner_name = pw->pw_name;
|
||||
} else {
|
||||
owner_name = "n/a";
|
||||
}
|
||||
|
||||
if (auto* gr = getgrgid(st.st_gid)) {
|
||||
group_name = gr->gr_name;
|
||||
} else {
|
||||
group_name = "n/a";
|
||||
}
|
||||
|
||||
m_mode = st.st_mode;
|
||||
|
||||
|
@ -115,8 +126,8 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
|
|||
}
|
||||
|
||||
properties.append({ "Size:", String::format("%zu bytes", st.st_size) });
|
||||
properties.append({ "Owner:", String::format("%s (%lu)", user_pw->pw_name, static_cast<u32>(user_pw->pw_uid)) });
|
||||
properties.append({ "Group:", String::format("%s (%lu)", group_gr->gr_name, static_cast<u32>(group_gr->gr_gid)) });
|
||||
properties.append({ "Owner:", String::format("%s (%lu)", owner_name.characters(), st.st_uid) });
|
||||
properties.append({ "Group:", String::format("%s (%lu)", group_name.characters(), st.st_gid) });
|
||||
properties.append({ "Created at:", GUI::FileSystemModel::timestamp_string(st.st_ctime) });
|
||||
properties.append({ "Last modified:", GUI::FileSystemModel::timestamp_string(st.st_mtime) });
|
||||
|
||||
|
@ -153,7 +164,7 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
|
|||
update();
|
||||
}
|
||||
|
||||
PropertiesDialog::~PropertiesDialog() { }
|
||||
PropertiesDialog::~PropertiesDialog() {}
|
||||
|
||||
void PropertiesDialog::update()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue