From d317309d8928acd8f3552fdce786939fc387c84e Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Mon, 6 Nov 2023 13:49:18 -0500 Subject: [PATCH] Everywhere: Unport Core::System::current_executable_path from new string Storing paths in AK::String is never correct. --- Ladybird/Android/src/main/cpp/RequestServerService.cpp | 2 +- Ladybird/Android/src/main/cpp/WebSocketService.cpp | 2 +- Ladybird/RequestServer/main.cpp | 2 +- Ladybird/Utilities.cpp | 2 +- Ladybird/WebSocket/main.cpp | 2 +- Userland/Libraries/LibCore/System.cpp | 8 ++++---- Userland/Libraries/LibCore/System.h | 2 +- Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp | 2 +- Userland/Utilities/pdf.cpp | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Ladybird/Android/src/main/cpp/RequestServerService.cpp b/Ladybird/Android/src/main/cpp/RequestServerService.cpp index 3856e2670e..231db0e05f 100644 --- a/Ladybird/Android/src/main/cpp/RequestServerService.cpp +++ b/Ladybird/Android/src/main/cpp/RequestServerService.cpp @@ -25,7 +25,7 @@ ErrorOr find_certificates(StringView serenity_resource_root) { auto cert_path = TRY(String::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root)); if (!FileSystem::exists(cert_path)) { - auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()).to_deprecated_string()); + auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path())); cert_path = TRY(String::formatted("{}/cacert.pem", LexicalPath(app_dir).parent())); if (!FileSystem::exists(cert_path)) diff --git a/Ladybird/Android/src/main/cpp/WebSocketService.cpp b/Ladybird/Android/src/main/cpp/WebSocketService.cpp index aad52eb5cf..87f7516812 100644 --- a/Ladybird/Android/src/main/cpp/WebSocketService.cpp +++ b/Ladybird/Android/src/main/cpp/WebSocketService.cpp @@ -21,7 +21,7 @@ ErrorOr find_certificates(StringView serenity_resource_root) { auto cert_path = TRY(String::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root)); if (!FileSystem::exists(cert_path)) { - auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()).to_deprecated_string()); + auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path())); cert_path = TRY(String::formatted("{}/cacert.pem", LexicalPath(app_dir).parent())); if (!FileSystem::exists(cert_path)) diff --git a/Ladybird/RequestServer/main.cpp b/Ladybird/RequestServer/main.cpp index a0934eea9f..8ac522fa4e 100644 --- a/Ladybird/RequestServer/main.cpp +++ b/Ladybird/RequestServer/main.cpp @@ -25,7 +25,7 @@ ErrorOr find_certificates(StringView serenity_resource_root) { auto cert_path = TRY(String::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root)); if (!FileSystem::exists(cert_path)) { - auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()).to_deprecated_string()); + auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path())); cert_path = TRY(String::formatted("{}/cacert.pem", LexicalPath(app_dir).parent())); if (!FileSystem::exists(cert_path)) diff --git a/Ladybird/Utilities.cpp b/Ladybird/Utilities.cpp index dc65dbdeb8..5897abe7a3 100644 --- a/Ladybird/Utilities.cpp +++ b/Ladybird/Utilities.cpp @@ -17,7 +17,7 @@ DeprecatedString s_serenity_resource_root; ErrorOr application_directory() { auto current_executable_path = TRY(Core::System::current_executable_path()); - auto dirname = LexicalPath::dirname(current_executable_path.to_deprecated_string()); + auto dirname = LexicalPath::dirname(current_executable_path); return String::from_deprecated_string(dirname); } diff --git a/Ladybird/WebSocket/main.cpp b/Ladybird/WebSocket/main.cpp index 0e2de2395b..783e2af26e 100644 --- a/Ladybird/WebSocket/main.cpp +++ b/Ladybird/WebSocket/main.cpp @@ -21,7 +21,7 @@ ErrorOr find_certificates(StringView serenity_resource_root) { auto cert_path = TRY(String::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root)); if (!FileSystem::exists(cert_path)) { - auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()).to_deprecated_string()); + auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path())); cert_path = TRY(String::formatted("{}/cacert.pem", LexicalPath(app_dir).parent())); if (!FileSystem::exists(cert_path)) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 08434654be..f7de49ee62 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -1806,7 +1806,7 @@ char** environment() #endif } -ErrorOr current_executable_path() +ErrorOr current_executable_path() { char path[4096] = {}; #if defined(AK_OS_LINUX) || defined(AK_OS_ANDROID) || defined(AK_OS_SERENITY) @@ -1827,9 +1827,9 @@ ErrorOr current_executable_path() return Error::from_syscall("proc_get_exe"sv, -errno); } #elif defined(AK_OS_DRAGONFLY) - return String::from_deprecated_string(TRY(readlink("/proc/curproc/file"sv))); + return TRY(readlink("/proc/curproc/file"sv)); #elif defined(AK_OS_SOLARIS) - return String::from_deprecated_string(TRY(readlink("/proc/self/path/a.out"sv))); + return TRY(readlink("/proc/self/path/a.out"sv)); #elif defined(AK_OS_FREEBSD) int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; size_t len = sizeof(path); @@ -1862,7 +1862,7 @@ ErrorOr current_executable_path() return Error::from_string_view("current_executable_path unknown"sv); #endif path[sizeof(path) - 1] = '\0'; - return String::from_utf8({ path, strlen(path) }); + return DeprecatedString { path, strlen(path) }; } ErrorOr allocate(size_t count, size_t size) diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 716b66ecf6..c170adbbb1 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -279,7 +279,7 @@ ErrorOr resolve_executable_from_environment(StringView filename, int fla char** environment(); -ErrorOr current_executable_path(); +ErrorOr current_executable_path(); ErrorOr allocate(size_t count, size_t size); diff --git a/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp b/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp index 78f3b4a36c..efa804192d 100644 --- a/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp +++ b/Userland/Libraries/LibWeb/HTML/WorkerAgent.cpp @@ -18,7 +18,7 @@ namespace { ErrorOr application_directory() { auto current_executable_path = TRY(Core::System::current_executable_path()); - auto dirname = LexicalPath::dirname(current_executable_path.to_deprecated_string()); + auto dirname = LexicalPath::dirname(current_executable_path); return String::from_deprecated_string(dirname); } diff --git a/Userland/Utilities/pdf.cpp b/Userland/Utilities/pdf.cpp index 0593e0a89c..c5b74e6829 100644 --- a/Userland/Utilities/pdf.cpp +++ b/Userland/Utilities/pdf.cpp @@ -224,7 +224,7 @@ static PDF::PDFErrorOr pdf_main(Main::Arguments arguments) #if !defined(AK_OS_SERENITY) if (debugging_stats || !render_path.is_empty()) { // Get from Build/lagom/bin/pdf to Base/res/fonts. - auto source_root = LexicalPath(MUST(Core::System::current_executable_path()).to_deprecated_string()).parent().parent().parent().parent().string(); + auto source_root = LexicalPath(MUST(Core::System::current_executable_path())).parent().parent().parent().parent().string(); Core::ResourceImplementation::install(make(TRY(String::formatted("{}/Base/res", source_root)))); } #endif