From bad2fe33ade89b058ffa40e95ab5ff5c77481120 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 4 Jan 2019 18:50:16 +0100 Subject: [PATCH] Fix crash when doing "ls -l" in the /proc/PID directory for a kernel process. --- Kernel/ProcFileSystem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Kernel/ProcFileSystem.cpp b/Kernel/ProcFileSystem.cpp index c9d995d1f9a..a4a4d2a9e78 100644 --- a/Kernel/ProcFileSystem.cpp +++ b/Kernel/ProcFileSystem.cpp @@ -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)