Skip to content

Commit 2db6b11

Browse files
committed
[fix](encrypt) wrong mode arg of encrypt and decrypt function make BE crash (apache#40726)
Not supported mode arg in sm4_encrypt and sm4_decrypt make BE crash. Intro by apache#37194
1 parent cecd214 commit 2db6b11

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

be/src/vec/functions/function_encryption.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ struct EncryptionAndDecryptTwoImpl {
244244
if (mode_arg.size != 0) {
245245
if (!aes_mode_map.contains(mode_str)) {
246246
all_insert_null = true;
247+
} else {
248+
encryption_mode = aes_mode_map.at(mode_str);
247249
}
248-
encryption_mode = aes_mode_map.at(mode_str);
249250
}
250251
const ColumnString::Offsets* offsets_column = &column->get_offsets();
251252
const ColumnString::Chars* chars_column = &column->get_chars();
@@ -371,13 +372,15 @@ struct EncryptionAndDecryptMultiImpl {
371372
if constexpr (is_sm_mode) {
372373
if (sm4_mode_map.count(mode_str) == 0) {
373374
all_insert_null = true;
375+
} else {
376+
encryption_mode = sm4_mode_map.at(mode_str);
374377
}
375-
encryption_mode = sm4_mode_map.at(mode_str);
376378
} else {
377379
if (aes_mode_map.count(mode_str) == 0) {
378380
all_insert_null = true;
381+
} else {
382+
encryption_mode = aes_mode_map.at(mode_str);
379383
}
380-
encryption_mode = aes_mode_map.at(mode_str);
381384
}
382385
}
383386

regression-test/data/query_p0/sql_functions/encryption_digest/test_encryption_function.out

+3
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,6 @@ zhang
272272
-- !sql56 --
273273
zhang
274274

275+
-- !sql57 --
276+
\N
277+

regression-test/suites/query_p0/sql_functions/encryption_digest/test_encryption_function.groovy

+3
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,7 @@ suite("test_encryption_function") {
226226
qt_sql54 """ select aes_decrypt(aes_encrypt(k,k1,k2, "AES_256_CFB"),k1,k2, "AES_256_CFB") from quantile_table2; """
227227
qt_sql55 """ select aes_decrypt(aes_encrypt("zhang",k1,k2, "AES_256_CFB"),k1,k2, "AES_256_CFB") from quantile_table2; """
228228
qt_sql56 """ select aes_decrypt(aes_encrypt("zhang",k1,k2, "AES_256_CFB"),k1,k2, "AES_256_CFB") from quantile_table2; """
229+
230+
//four arg (column/const) with wrong mode
231+
qt_sql57 """ select sm4_decrypt(sm4_encrypt(k,"doris","abcdefghij", "SM4_128_CBC"),"doris","abcdefghij","SM4_555_CBC") from quantile_table2; """
229232
}

0 commit comments

Comments
 (0)