1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 16:57:35 +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:
Andreas Kling 2020-04-29 19:35:20 +02:00
parent 9f32d71782
commit 85fd0d2187

View file

@ -94,9 +94,20 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
return; return;
} }
struct passwd* user_pw = getpwuid(st.st_uid); String owner_name;
struct group* group_gr = getgrgid(st.st_gid); String group_name;
ASSERT(user_pw && group_gr);
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; 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({ "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({ "Owner:", String::format("%s (%lu)", owner_name.characters(), st.st_uid) });
properties.append({ "Group:", String::format("%s (%lu)", group_gr->gr_name, static_cast<u32>(group_gr->gr_gid)) }); 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({ "Created at:", GUI::FileSystemModel::timestamp_string(st.st_ctime) });
properties.append({ "Last modified:", GUI::FileSystemModel::timestamp_string(st.st_mtime) }); properties.append({ "Last modified:", GUI::FileSystemModel::timestamp_string(st.st_mtime) });
@ -153,7 +164,7 @@ PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, boo
update(); update();
} }
PropertiesDialog::~PropertiesDialog() { } PropertiesDialog::~PropertiesDialog() {}
void PropertiesDialog::update() void PropertiesDialog::update()
{ {