summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibTLS
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2023-04-27 21:21:19 +0330
committerAndreas Kling <kling@serenityos.org>2023-04-28 05:55:20 +0200
commit7e6341587ba174309989ddebf7cc6a489751b0a8 (patch)
treec6c3c2cd4473340f03c513c8995a4a7751f6237b /Userland/Libraries/LibTLS
parentcc35bab143e022baf570e910c0a14dbf62ff2cdd (diff)
downloadserenity-7e6341587ba174309989ddebf7cc6a489751b0a8.zip
AK+Everywhere: Disallow Error::from_string_view(FooString)
That pattern seems to show up a lot in code written by people that aren't intimately familiar with the lifetime model of Error and Strings. This commit makes the compiler detect it and present a more helpful diagnostic than "garbage string at runtime".
Diffstat (limited to 'Userland/Libraries/LibTLS')
-rw-r--r--Userland/Libraries/LibTLS/Certificate.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/Userland/Libraries/LibTLS/Certificate.cpp b/Userland/Libraries/LibTLS/Certificate.cpp
index 839538cc74..dbd3f9cf30 100644
--- a/Userland/Libraries/LibTLS/Certificate.cpp
+++ b/Userland/Libraries/LibTLS/Certificate.cpp
@@ -12,11 +12,16 @@
#include <LibCrypto/ASN1/DER.h>
#include <LibCrypto/ASN1/PEM.h>
+namespace {
+static String s_error_string;
+}
+
namespace TLS {
-#define ERROR_WITH_SCOPE(error) \
- do { \
- return Error::from_string_view(TRY(String::formatted("{}: {}", current_scope, error))); \
+#define ERROR_WITH_SCOPE(error) \
+ do { \
+ s_error_string = TRY(String::formatted("{}: {}", current_scope, error)); \
+ return Error::from_string_view(s_error_string.bytes_as_string_view()); \
} while (0)
#define ENTER_TYPED_SCOPE(tag_kind_name, scope) \
@@ -77,7 +82,7 @@ static ErrorOr<SupportedGroup> oid_to_curve(Vector<int> curve)
else if (curve == curve_prime256)
return SupportedGroup::SECP256R1;
- return Error::from_string_view(TRY(String::formatted("Unknown curve oid {}", curve)));
+ return Error::from_string_view("Unknown curve oid"sv);
}
static ErrorOr<Crypto::UnsignedBigInteger> parse_version(Crypto::ASN1::Decoder& decoder, Vector<StringView> current_scope)