summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorGleb Shchepa <gshchepa@mysql.com>2008-06-27 20:56:41 +0500
committerGleb Shchepa <gshchepa@mysql.com>2008-06-27 20:56:41 +0500
commitb83b4697d229c78d85954b219cfed5caf428b20e (patch)
tree4583c35b2f4ba5f73996dc2dde6b0bccfe9c80e5 /sql/item.cc
parent49417ad7c8e45792f5baafb9514b10684daba527 (diff)
downloadmariadb-git-b83b4697d229c78d85954b219cfed5caf428b20e.tar.gz
backport from 6.0
Bug#35658 (An empty binary value leads to mysqld crash) Before this fix, the following token b'' caused the parser to crash when reading the binary value from the empty string. The crash was caused by: ptr+= max_length - 1; because max_length is unsigned and was 0, causing an overflow. With this fix, an empty binary literal b'' is parsed as a binary value 0, in Item_bin_string. mysql-test/r/varbinary.result: Bug#35658 (An empty binary value leads to mysqld crash) mysql-test/t/varbinary.test: Bug#35658 (An empty binary value leads to mysqld crash) sql/item.cc: Bug#35658 (An empty binary value leads to mysqld crash)
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc29
1 files changed, 18 insertions, 11 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 9ff1f8c0084..bf447581afa 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -5013,21 +5013,28 @@ Item_bin_string::Item_bin_string(const char *str, uint str_length)
if (!ptr)
return;
str_value.set(ptr, max_length, &my_charset_bin);
- ptr+= max_length - 1;
- ptr[1]= 0; // Set end null for string
- for (; end >= str; end--)
+
+ if (max_length > 0)
{
- if (power == 256)
+ ptr+= max_length - 1;
+ ptr[1]= 0; // Set end null for string
+ for (; end >= str; end--)
{
- power= 1;
- *ptr--= bits;
- bits= 0;
+ if (power == 256)
+ {
+ power= 1;
+ *ptr--= bits;
+ bits= 0;
+ }
+ if (*end == '1')
+ bits|= power;
+ power<<= 1;
}
- if (*end == '1')
- bits|= power;
- power<<= 1;
+ *ptr= (char) bits;
}
- *ptr= (char) bits;
+ else
+ ptr[0]= 0;
+
collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
fixed= 1;
}