You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by ya...@apache.org on 2021/09/14 03:20:05 UTC

[incubator-doris] branch master updated: [Bug] Fix aes_decrypt to handle null input correctly. (#6636)

This is an automated email from the ASF dual-hosted git repository.

yangzhg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 020282e  [Bug] Fix aes_decrypt to handle null input correctly. (#6636)
020282e is described below

commit 020282e885f5ce1339cbe1e5ea72bf55a49ddf27
Author: Cui Kaifeng <48...@users.noreply.github.com>
AuthorDate: Tue Sep 14 11:19:55 2021 +0800

    [Bug] Fix aes_decrypt to handle null input correctly. (#6636)
---
 be/src/exprs/encryption_functions.cpp       |  4 ++--
 be/test/exprs/encryption_functions_test.cpp | 24 +++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/be/src/exprs/encryption_functions.cpp b/be/src/exprs/encryption_functions.cpp
index 29c14d7..6aa3140 100644
--- a/be/src/exprs/encryption_functions.cpp
+++ b/be/src/exprs/encryption_functions.cpp
@@ -33,7 +33,7 @@ void EncryptionFunctions::init() {}
 
 StringVal EncryptionFunctions::aes_encrypt(FunctionContext* ctx, const StringVal& src,
                                            const StringVal& key) {
-    if (src.len == 0) {
+    if (src.len == 0 || src.is_null) {
         return StringVal::null();
     }
 
@@ -53,7 +53,7 @@ StringVal EncryptionFunctions::aes_encrypt(FunctionContext* ctx, const StringVal
 
 StringVal EncryptionFunctions::aes_decrypt(FunctionContext* ctx, const StringVal& src,
                                            const StringVal& key) {
-    if (src.len == 0) {
+    if (src.len == 0 || src.is_null) {
         return StringVal::null();
     }
 
diff --git a/be/test/exprs/encryption_functions_test.cpp b/be/test/exprs/encryption_functions_test.cpp
index c73b9e7..2c13e05 100644
--- a/be/test/exprs/encryption_functions_test.cpp
+++ b/be/test/exprs/encryption_functions_test.cpp
@@ -76,6 +76,28 @@ TEST_F(EncryptionFunctionsTest, to_base64) {
     }
 }
 
+TEST_F(EncryptionFunctionsTest, aes_decrypt) {
+    std::unique_ptr<doris_udf::FunctionContext> context(new doris_udf::FunctionContext());
+    {
+        StringVal encryptWord = EncryptionFunctions::aes_encrypt(context.get(), doris_udf::StringVal("hello"),
+                doris_udf::StringVal("key"));
+        StringVal result = EncryptionFunctions::aes_decrypt(context.get(), encryptWord,
+                doris_udf::StringVal("key"));
+        StringVal expected = doris_udf::StringVal("hello");
+        ASSERT_EQ(expected, result);
+    }
+    {
+        StringVal encryptWord = EncryptionFunctions::aes_encrypt(context.get(), doris_udf::StringVal("hello"),
+                doris_udf::StringVal("key"));
+        encryptWord.is_null = true;
+        StringVal result = EncryptionFunctions::aes_decrypt(context.get(), encryptWord,
+                doris_udf::StringVal("key"));
+        StringVal expected = doris_udf::StringVal::null();
+        ASSERT_EQ(expected, result);
+    }
+
+}
+
 } // namespace doris
 
 int main(int argc, char** argv) {
@@ -86,4 +108,4 @@ int main(int argc, char** argv) {
     }
     ::testing::InitGoogleTest(&argc, argv);
     return RUN_ALL_TESTS();
-}
\ No newline at end of file
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org