Skip to content
Permalink
Browse files
MDEV-25343 add read secret size in file key plugin
  • Loading branch information
dingweiqings authored and grooverdan committed Oct 19, 2022
1 parent 64d85c3 commit cee7175
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
@@ -0,0 +1,10 @@
call mtr.add_suppression("the secret file has incorrect length");
call mtr.add_suppression("Plugin 'file_key_management' init function returned error");
call mtr.add_suppression("Plugin 'file_key_management' registration.*failed");
FOUND 1 /the secret file has incorrect length/ in mysqld.1.err
create table t1(c1 bigint not null, b char(200)) engine=innodb encrypted=yes encryption_key_id=1;
ERROR HY000: Can't create table `test`.`t1` (errno: 140 "Wrong create options")
select plugin_status from information_schema.plugins
where plugin_name = 'file_key_management';
plugin_status
# Test checks if opening an too large secret does not crash the server.
@@ -0,0 +1,4 @@
secretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecret
secretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecret
secretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecret

@@ -0,0 +1,3 @@
--loose-file-key-management-filekey=FILE:$MTR_SUITE_DIR/t/filekeys-data-too-long.key
--loose-file-key-management-filename=$MTR_SUITE_DIR/t/filekeys-data.enc

@@ -0,0 +1,4 @@
let SEARCH_PATTERN=the secret file has incorrect length;
source filekeys_badtest.inc;

--echo # Test checks if opening an too large secret does not crash the server.
@@ -174,13 +174,24 @@ bool Parser::read_filekey(const char *filekey, char *secret)
return 1;
}

int len= read(f, secret, MAX_SECRET_SIZE);
int len= read(f, secret, MAX_SECRET_SIZE + 1);
if (len <= 0)
{
my_error(EE_READ,ME_ERROR_LOG, filekey, errno);
close(f);
return 1;
}

if (len > MAX_SECRET_SIZE)
{
my_printf_error(EE_READ,
"Cannot decrypt %s, the secret file has incorrect length, "
"max secret size is %dB ",
ME_ERROR_LOG, filekey, MAX_SECRET_SIZE);
close(f);
return 1;
}

close(f);
while (secret[len - 1] == '\r' || secret[len - 1] == '\n') len--;
secret[len]= '\0';

0 comments on commit cee7175

Please sign in to comment.