summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-09-12 14:29:23 -0700
committerAndreas Kling <kling@serenityos.org>2021-09-13 00:02:42 +0200
commitb8cad2c9b998875033ebe656a96f10acceeae61a (patch)
tree06f2fd72f64370b7d229632e957578825e2b5a31 /Userland/Libraries/LibCore
parent43f4292ca00c323062a6c16614c29230f9d2cb92 (diff)
downloadserenity-b8cad2c9b998875033ebe656a96f10acceeae61a.zip
LibCore: Switch to AK::secure_zero instead of platform specific APIs
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r--Userland/Libraries/LibCore/SecretString.cpp21
1 files changed, 5 insertions, 16 deletions
diff --git a/Userland/Libraries/LibCore/SecretString.cpp b/Userland/Libraries/LibCore/SecretString.cpp
index 890e9e5d76..c80645a7fb 100644
--- a/Userland/Libraries/LibCore/SecretString.cpp
+++ b/Userland/Libraries/LibCore/SecretString.cpp
@@ -5,12 +5,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <AK/Platform.h>
+#include <AK/Memory.h>
#include <LibCore/SecretString.h>
-#if defined(AK_OS_MACOS)
-# define __STDC_WANT_LIB_EXT1__ 1
-#endif
-#include <string.h>
namespace Core {
@@ -19,12 +15,9 @@ SecretString SecretString::take_ownership(char*& cstring, size_t length)
auto buffer = ByteBuffer::copy(cstring, length);
VERIFY(buffer.has_value());
-#if defined(AK_OS_MACOS)
- memset_s(cstring, length, 0, length);
-#else
- explicit_bzero(cstring, length);
-#endif
+ secure_zero(cstring, length);
free(cstring);
+ cstring = nullptr;
return SecretString(buffer.release_value());
}
@@ -41,14 +34,10 @@ SecretString::SecretString(ByteBuffer&& buffer)
SecretString::~SecretString()
{
- // Note: We use explicit_bzero to avoid the zeroing from being optimized out by the compiler,
+ // Note: We use secure_zero to avoid the zeroing from being optimized out by the compiler,
// which is possible if memset was to be used here.
if (!m_secure_buffer.is_empty()) {
-#if defined(AK_OS_MACOS)
- memset_s(m_secure_buffer.data(), m_secure_buffer.size(), 0, m_secure_buffer.size());
-#else
- explicit_bzero(m_secure_buffer.data(), m_secure_buffer.capacity());
-#endif
+ secure_zero(m_secure_buffer.data(), m_secure_buffer.capacity());
}
}