Fix crash when doing "ls -l" in the /proc/PID directory for a kernel process.

This commit is contained in:
Andreas Kling 2019-01-04 18:50:16 +01:00
parent 0d36281162
commit bad2fe33ad
Notes: sideshowbarker 2024-07-19 16:06:04 +09:00

View File

@ -32,6 +32,8 @@ ProcFS::~ProcFS()
ByteBuffer procfs$pid_fds(Process& process)
{
ProcessInspectionHandle handle(process);
if (process.number_of_open_file_descriptors() == 0)
return { };
char* buffer;
auto stringImpl = StringImpl::create_uninitialized(process.number_of_open_file_descriptors() * 80, buffer);
memset(buffer, 0, stringImpl->length());
@ -181,7 +183,8 @@ void ProcFS::add_process(Process& process)
add_file(create_generated_file("fds", [&process] { return procfs$pid_fds(process); }), dir.index());
if (process.executable_inode())
add_file(create_generated_file("exe", [&process] { return procfs$pid_exe(process); }, 00120777), dir.index());
add_file(create_generated_file("cwd", [&process] { return procfs$pid_cwd(process); }, 00120777), dir.index());
if (process.cwd_inode())
add_file(create_generated_file("cwd", [&process] { return procfs$pid_cwd(process); }, 00120777), dir.index());
}
void ProcFS::remove_process(Process& process)