summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorCameron Youell <cameronyouell@gmail.com>2023-03-23 00:11:48 +1100
committerLinus Groh <mail@linusgroh.de>2023-03-22 14:04:24 +0000
commita8cd6c396b51c49c310218dead50b1e7b6d14aef (patch)
treea16a4d85c0f7f301e2e39268d444555a7dd037d1 /Userland/Libraries
parent26a4e4d23d1c62203f39dc7325e7309d477bcb63 (diff)
downloadserenity-a8cd6c396b51c49c310218dead50b1e7b6d14aef.zip
LibFileSystem: Fix leak in `read_path`
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibFileSystem/FileSystem.cpp6
1 files 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 <LibCore/DirIterator.h>
#include <LibCore/System.h>
#include <LibFileSystem/FileSystem.h>
+#include <limits.h>
#ifdef AK_OS_SERENITY
# include <serenity.h>
@@ -46,13 +47,14 @@ ErrorOr<String> 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)