From a8cd6c396b51c49c310218dead50b1e7b6d14aef Mon Sep 17 00:00:00 2001 From: Cameron Youell Date: Thu, 23 Mar 2023 00:11:48 +1100 Subject: [PATCH] LibFileSystem: Fix leak in `read_path` --- Userland/Libraries/LibFileSystem/FileSystem.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibFileSystem/FileSystem.cpp b/Userland/Libraries/LibFileSystem/FileSystem.cpp index 2e181fa937..908200c2e5 100644 --- a/Userland/Libraries/LibFileSystem/FileSystem.cpp +++ b/Userland/Libraries/LibFileSystem/FileSystem.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #ifdef AK_OS_SERENITY # include @@ -46,13 +47,14 @@ ErrorOr real_path(StringView path) if (path.is_null()) return Error::from_errno(ENOENT); + char buffer[PATH_MAX]; DeprecatedString dep_path = path; - auto* real_path = realpath(dep_path.characters(), nullptr); + auto* real_path = realpath(dep_path.characters(), buffer); if (!real_path) return Error::from_syscall("realpath"sv, -errno); - return TRY(String::from_deprecated_string({ real_path })); + return TRY(String::from_utf8({ real_path, strlen(real_path) })); } bool exists(StringView path)