Skip to content

Commit

Permalink
Fix msan findings in 01683_codec_encrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
rschu1ze committed Apr 5, 2024
1 parent 58c3aa7 commit 979e06c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Compression/CompressionCodecEncrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,17 @@ size_t encrypt(std::string_view plaintext, char * ciphertext_and_tag, Encryption
static_cast<int32_t>(plaintext.size())); ok == 0)
throw Exception::createDeprecated(lastErrorString(), ErrorCodes::OPENSSL_ERROR);

__msan_unpoison(ciphertext_and_tag, out_len); /// OpenSSL uses assembly which evades msan's analysis

ciphertext_len = out_len;

if (int ok = EVP_EncryptFinal_ex(ctx,
reinterpret_cast<uint8_t *>(ciphertext_and_tag) + out_len,
reinterpret_cast<int32_t *>(&out_len)); ok == 0)
throw Exception::createDeprecated(lastErrorString(), ErrorCodes::OPENSSL_ERROR);

__msan_unpoison(ciphertext_and_tag, out_len); /// OpenSSL uses assembly which evades msan's analysis

ciphertext_len += out_len;

/// Get the tag
Expand Down Expand Up @@ -235,12 +239,16 @@ size_t decrypt(std::string_view ciphertext, char * plaintext, EncryptionMethod m
static_cast<int32_t>(ciphertext.size()) - tag_size); ok == 0)
throw Exception::createDeprecated(lastErrorString(), ErrorCodes::OPENSSL_ERROR);

__msan_unpoison(plaintext, out_len); /// OpenSSL uses assembly which evades msan's analysis

plaintext_len = out_len;

if (int ok = EVP_DecryptFinal_ex(ctx,
reinterpret_cast<uint8_t *>(plaintext) + out_len,
reinterpret_cast<int32_t *>(&out_len)); ok == 0)
throw Exception::createDeprecated(lastErrorString(), ErrorCodes::OPENSSL_ERROR);

__msan_unpoison(plaintext, out_len); /// OpenSSL uses assembly which evades msan's analysis
}
catch (...)
{
Expand Down

0 comments on commit 979e06c

Please sign in to comment.