浏览代码

LibCore: Propagate errors in SecretString

Undefine 2 年之前
父节点
当前提交
ccc871e608

+ 1 - 1
Userland/Libraries/LibCore/GetPassword.cpp

@@ -40,6 +40,6 @@ ErrorOr<SecretString> get_password(StringView prompt)
     // Remove trailing '\n' read by getline().
     password[line_length - 1] = '\0';
 
-    return SecretString::take_ownership(password, line_length);
+    return TRY(SecretString::take_ownership(password, line_length));
 }
 }

+ 2 - 2
Userland/Libraries/LibCore/SecretString.cpp

@@ -10,9 +10,9 @@
 
 namespace Core {
 
-SecretString SecretString::take_ownership(char*& cstring, size_t length)
+ErrorOr<SecretString> SecretString::take_ownership(char*& cstring, size_t length)
 {
-    auto buffer = ByteBuffer::copy(cstring, length).release_value_but_fixme_should_propagate_errors();
+    auto buffer = TRY(ByteBuffer::copy(cstring, length));
 
     secure_zero(cstring, length);
     free(cstring);

+ 1 - 1
Userland/Libraries/LibCore/SecretString.h

@@ -16,7 +16,7 @@ class SecretString {
     AK_MAKE_NONCOPYABLE(SecretString);
 
 public:
-    [[nodiscard]] static SecretString take_ownership(char*&, size_t);
+    [[nodiscard]] static ErrorOr<SecretString> take_ownership(char*&, size_t);
     [[nodiscard]] static SecretString take_ownership(ByteBuffer&&);
 
     [[nodiscard]] bool is_empty() const { return m_secure_buffer.is_empty(); }