summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore/SecretString.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibCore/SecretString.cpp')
-rw-r--r--Userland/Libraries/LibCore/SecretString.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/SecretString.cpp b/Userland/Libraries/LibCore/SecretString.cpp
index f8cbb3392e..4763936a81 100644
--- a/Userland/Libraries/LibCore/SecretString.cpp
+++ b/Userland/Libraries/LibCore/SecretString.cpp
@@ -30,6 +30,13 @@ SecretString SecretString::take_ownership(ByteBuffer&& buffer)
SecretString::SecretString(ByteBuffer&& buffer)
: m_secure_buffer(move(buffer))
{
+ // SecretString is currently only used to provide the character data to invocations to crypt(),
+ // which requires a NUL-terminated string. To ensure this operation avoids a buffer overrun,
+ // append a NUL terminator here if there isn't already one.
+ if (m_secure_buffer.is_empty() || (m_secure_buffer[m_secure_buffer.size() - 1] != 0)) {
+ u8 nul = '\0';
+ m_secure_buffer.append(&nul, 1);
+ }
}
SecretString::~SecretString()