Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
6aff5fa2
Commit
6aff5fa2
authored
Mar 26, 2018
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-15619 using CONVERT() inside AES_ENCRYPT() in an UPDATE corrupts data
parent
a2e47f8c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
6 deletions
+90
-6
mysql-test/r/func_str.result
mysql-test/r/func_str.result
+37
-0
mysql-test/t/func_str.test
mysql-test/t/func_str.test
+36
-0
sql/item_strfunc.cc
sql/item_strfunc.cc
+2
-2
sql/item_strfunc.h
sql/item_strfunc.h
+15
-4
No files found.
mysql-test/r/func_str.result
View file @
6aff5fa2
...
...
@@ -4551,3 +4551,40 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select char(0xdf) AS `CHAR(0xDF)`
#
# MDEV-15619 using CONVERT() inside AES_ENCRYPT() in an UPDATE corrupts data
#
CREATE TABLE t1 (
id int(11) NOT NULL,
session_id varchar(255) DEFAULT NULL,
directory mediumtext,
checksum int(10) DEFAULT NULL,
last_update datetime DEFAULT NULL,
PRIMARY KEY (id),
KEY lastupdate (last_update)
) DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES (1,'',NULL,38391,'2017-06-24 07:35:28');
UPDATE t1 SET directory = AES_ENCRYPT(CONVERT('test stringrererejrjerjehrjekhrjkehrjkehrkjehrjkerhkjehrjekrhkjehrkjerhjkehrkjehrkjehrjkehrjkehrjkehrjkerjkehrjkehrjkehrjke rekjhrejrejhrjehgrehjgrhjerjhegrjherejhgrjhegrjehgrjhegrejhrgjehgrjhegrjhegrjhergjhegrjhegrhjegrjerhthkjjkdhjkgdfjkgjkdgdjkfjkhgjkfdhjgjkfdghkjdfghkjfdghfjkdghkdjfghdkjfghfjkdghfkjdghkjfdghfkjdghfkdjghfkjdghfdjkghjkdfhgdfjkghfjkdghfjkdghfjdkghfjkdghkfjdghfkjdghfkjdghkjdfghfjdkghjkfdghkjdfhgjkdfhgjkfdhgkjfdghkfjdhgkjfdgdjkejktjherjthkjrethkjrethjkerthjkerhtjkerhtkjerhtjkerhtjkerhtjkrehtkjerhtkjrehtjkrehtkjrehtkjerhtkjerhtjkrehtkjrehtjkrehtkjrethjkrethkjrehtkjethjkerhtjkrehtjkretkjerhtkjrehtjkerhtjkrehtjrehtkjrekjtrfgdsfgdhjsghjgfdhjsfhjdfgdhjshjdshjfghjdsfgjhsfgjhsdfgjhdsfgjdhsfgsjhfgjhsdfgsdjhfgjdhsfdjshfgdsjhfgjsdhfdjshfgdjhsfgdjshfgjdhsfgjhsdfgjhsdgfjhsdgfjhdsgfjhsgfjhsdgfjhdsgfhjsdehkjthrkjethjkre' USING latin1), '95F5A1F52A554'), last_update= NOW();
SELECT directory IS NULL FROM t1;
directory IS NULL
0
DROP TABLE t1;
CREATE TABLE t1 (
id int(11) NOT NULL PRIMARY KEY,
directory mediumtext
) DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES (1,AES_ENCRYPT(CONVERT(REPEAT('a',800) USING latin1),'95F5A1F52A554'));
SELECT AES_DECRYPT(directory,'95F5A1F52A554') FROM t1;
AES_DECRYPT(directory,'95F5A1F52A554')
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
DROP TABLE t1;
SET @enc=AES_ENCRYPT(REPEAT(_latin1'a',800),'95F5A1F52A554');
CREATE TABLE t1 (
id int(11) NOT NULL PRIMARY KEY,
directory mediumtext
) DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES (1,AES_DECRYPT(CONVERT(@enc USING binary),'95F5A1F52A554'));
SELECT * FROM t1;
id directory
1 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
DROP TABLE t1;
mysql-test/t/func_str.test
View file @
6aff5fa2
...
...
@@ -1754,3 +1754,39 @@ EXECUTE stmt;
EXPLAIN
EXTENDED
SELECT
CHAR
(
0xDF
USING
latin1
);
EXPLAIN
EXTENDED
SELECT
CHAR
(
0xDF
USING
`binary`
);
EXPLAIN
EXTENDED
SELECT
CHAR
(
0xDF
);
--
echo
#
--
echo
# MDEV-15619 using CONVERT() inside AES_ENCRYPT() in an UPDATE corrupts data
--
echo
#
CREATE
TABLE
t1
(
id
int
(
11
)
NOT
NULL
,
session_id
varchar
(
255
)
DEFAULT
NULL
,
directory
mediumtext
,
checksum
int
(
10
)
DEFAULT
NULL
,
last_update
datetime
DEFAULT
NULL
,
PRIMARY
KEY
(
id
),
KEY
lastupdate
(
last_update
)
)
DEFAULT
CHARSET
=
latin1
;
INSERT
INTO
t1
VALUES
(
1
,
''
,
NULL
,
38391
,
'2017-06-24 07:35:28'
);
UPDATE
t1
SET
directory
=
AES_ENCRYPT
(
CONVERT
(
'test stringrererejrjerjehrjekhrjkehrjkehrkjehrjkerhkjehrjekrhkjehrkjerhjkehrkjehrkjehrjkehrjkehrjkehrjkerjkehrjkehrjkehrjke rekjhrejrejhrjehgrehjgrhjerjhegrjherejhgrjhegrjehgrjhegrejhrgjehgrjhegrjhegrjhergjhegrjhegrhjegrjerhthkjjkdhjkgdfjkgjkdgdjkfjkhgjkfdhjgjkfdghkjdfghkjfdghfjkdghkdjfghdkjfghfjkdghfkjdghkjfdghfkjdghfkdjghfkjdghfdjkghjkdfhgdfjkghfjkdghfjkdghfjdkghfjkdghkfjdghfkjdghfkjdghkjdfghfjdkghjkfdghkjdfhgjkdfhgjkfdhgkjfdghkfjdhgkjfdgdjkejktjherjthkjrethkjrethjkerthjkerhtjkerhtkjerhtjkerhtjkerhtjkrehtkjerhtkjrehtjkrehtkjrehtkjerhtkjerhtjkrehtkjrehtjkrehtkjrethjkrethkjrehtkjethjkerhtjkrehtjkretkjerhtkjrehtjkerhtjkrehtjrehtkjrekjtrfgdsfgdhjsghjgfdhjsfhjdfgdhjshjdshjfghjdsfgjhsfgjhsdfgjhdsfgjdhsfgsjhfgjhsdfgsdjhfgjdhsfdjshfgdsjhfgjsdhfdjshfgdjhsfgdjshfgjdhsfgjhsdfgjhsdgfjhsdgfjhdsgfjhsgfjhsdgfjhdsgfhjsdehkjthrkjethjkre'
USING
latin1
),
'95F5A1F52A554'
),
last_update
=
NOW
();
SELECT
directory
IS
NULL
FROM
t1
;
DROP
TABLE
t1
;
CREATE
TABLE
t1
(
id
int
(
11
)
NOT
NULL
PRIMARY
KEY
,
directory
mediumtext
)
DEFAULT
CHARSET
=
latin1
;
INSERT
INTO
t1
VALUES
(
1
,
AES_ENCRYPT
(
CONVERT
(
REPEAT
(
'a'
,
800
)
USING
latin1
),
'95F5A1F52A554'
));
SELECT
AES_DECRYPT
(
directory
,
'95F5A1F52A554'
)
FROM
t1
;
DROP
TABLE
t1
;
SET
@
enc
=
AES_ENCRYPT
(
REPEAT
(
_latin1
'a'
,
800
),
'95F5A1F52A554'
);
CREATE
TABLE
t1
(
id
int
(
11
)
NOT
NULL
PRIMARY
KEY
,
directory
mediumtext
)
DEFAULT
CHARSET
=
latin1
;
INSERT
INTO
t1
VALUES
(
1
,
AES_DECRYPT
(
CONVERT
(
@
enc
USING
binary
),
'95F5A1F52A554'
));
SELECT
*
FROM
t1
;
DROP
TABLE
t1
;
sql/item_strfunc.cc
View file @
6aff5fa2
...
...
@@ -379,7 +379,7 @@ String *Item_func_aes_encrypt::val_str(String *str2)
DBUG_ASSERT
(
fixed
==
1
);
char
key_buff
[
80
];
String
tmp_key_value
(
key_buff
,
sizeof
(
key_buff
),
system_charset_info
);
String
*
sptr
=
args
[
0
]
->
val_str
(
&
str
_value
);
// String to encrypt
String
*
sptr
=
args
[
0
]
->
val_str
(
&
tmp
_value
);
// String to encrypt
String
*
key
=
args
[
1
]
->
val_str
(
&
tmp_key_value
);
// key
int
aes_length
;
if
(
sptr
&&
key
)
// we need both arguments to be not NULL
...
...
@@ -418,7 +418,7 @@ String *Item_func_aes_decrypt::val_str(String *str)
String
*
sptr
,
*
key
;
DBUG_ENTER
(
"Item_func_aes_decrypt::val_str"
);
sptr
=
args
[
0
]
->
val_str
(
&
str
_value
);
// String to decrypt
sptr
=
args
[
0
]
->
val_str
(
&
tmp
_value
);
// String to decrypt
key
=
args
[
1
]
->
val_str
(
&
tmp_key_value
);
// Key
if
(
sptr
&&
key
)
// Need to have both arguments not NULL
{
...
...
sql/item_strfunc.h
View file @
6aff5fa2
...
...
@@ -134,19 +134,30 @@ class Item_func_from_base64 :public Item_str_func
};
class
Item_func_aes_encrypt
:
public
Item_str_func
class
Item_aes_crypt
:
public
Item_str_func
{
protected:
String
tmp_value
;
public:
Item_aes_crypt
(
Item
*
a
,
Item
*
b
)
:
Item_str_func
(
a
,
b
)
{}
};
class
Item_func_aes_encrypt
:
public
Item_aes_crypt
{
public:
Item_func_aes_encrypt
(
Item
*
a
,
Item
*
b
)
:
Item_str_func
(
a
,
b
)
{}
Item_func_aes_encrypt
(
Item
*
a
,
Item
*
b
)
:
Item_aes_crypt
(
a
,
b
)
{}
String
*
val_str
(
String
*
);
void
fix_length_and_dec
();
const
char
*
func_name
()
const
{
return
"aes_encrypt"
;
}
};
class
Item_func_aes_decrypt
:
public
Item_
str_func
class
Item_func_aes_decrypt
:
public
Item_
aes_crypt
{
public:
Item_func_aes_decrypt
(
Item
*
a
,
Item
*
b
)
:
Item_str_func
(
a
,
b
)
{}
Item_func_aes_decrypt
(
Item
*
a
,
Item
*
b
)
:
Item_aes_crypt
(
a
,
b
)
{}
String
*
val_str
(
String
*
);
void
fix_length_and_dec
();
const
char
*
func_name
()
const
{
return
"aes_decrypt"
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment