summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorWeijun Huang <huangweijun1001@gmail.com>2023-03-11 11:06:03 +0100
committerDaniel Black <daniel@mariadb.org>2023-03-31 14:53:50 +1100
commitf70de1451ba24e0459edcdbe2e67e3df5f348050 (patch)
tree9b555c561f0a0b5d59219d2206e7af8be6785c3f /sql
parenta6780df49b443b172124e7e881ed0bea54d75907 (diff)
downloadmariadb-git-f70de1451ba24e0459edcdbe2e67e3df5f348050.tar.gz
MDEV-30351 crash in Item_func_left::val_str
When using LEFT() function with a string that is without a charset, the function crashes. This is because the function assumes that the string has a charset, and tries to use it to calculate the length of the string. Two functions, UNHEX and WEIGHT_STRING, returned a string without the charset being set to a not null value. The fix is to set charset when calling val_str on these two functions. Reviewed-by: Alexander Barkov <bar@mariadb.com> Reviewed-by: Daniel Black <daniel@mariadb.org>
Diffstat (limited to 'sql')
-rw-r--r--sql/item_strfunc.cc2
1 files changed, 2 insertions, 0 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index a57fbd7bebc..f95f4795820 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -3729,6 +3729,7 @@ String *Item_func_weight_string::val_str(String *str)
flags);
DBUG_ASSERT(frm_length <= tmp_length);
+ str->set_charset(&my_charset_bin);
str->length(frm_length);
null_value= 0;
return str;
@@ -3808,6 +3809,7 @@ String *Item_func_unhex::val_str(String *str)
from= res->ptr();
null_value= 0;
+ str->set_charset(&my_charset_bin);
str->length(length);
to= (char*) str->ptr();
if (res->length() % 2)