summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorkurt <dingweiqings@163.com>2022-09-21 11:29:07 +0800
committerDaniel Black <daniel@mariadb.org>2022-10-21 15:54:17 +1100
commite11661a4a2c0d50d78b86dac71a0e3d226f0ddcf (patch)
tree59671c09f467614638627f9c22670782f24d43e0 /plugin
parent9de37e07de860fdbaade1de482692a9221fbcc98 (diff)
downloadmariadb-git-e11661a4a2c0d50d78b86dac71a0e3d226f0ddcf.tar.gz
MDEV-25343 Error log message not helpful when filekey is too long
Add a test related to the Encrypted Key File by following instructions in kb example https://mariadb.com/kb/en/file-key-management-encryption-plugin/#creating-the-key-file Reviewed by Daniel Black (with minor formatting and re-org of duplicate close(f) calls).
Diffstat (limited to 'plugin')
-rw-r--r--plugin/file_key_management/parser.cc15
1 files changed, 12 insertions, 3 deletions
diff --git a/plugin/file_key_management/parser.cc b/plugin/file_key_management/parser.cc
index 5a9e5e55d63..ec1b528da24 100644
--- a/plugin/file_key_management/parser.cc
+++ b/plugin/file_key_management/parser.cc
@@ -170,19 +170,28 @@ bool Parser::read_filekey(const char *filekey, char *secret)
int f= open(filekey, O_RDONLY|O_BINARY);
if (f == -1)
{
- my_error(EE_FILENOTFOUND,ME_ERROR_LOG, filekey, errno);
+ my_error(EE_FILENOTFOUND, ME_ERROR_LOG, filekey, errno);
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);
+ my_error(EE_READ, ME_ERROR_LOG, filekey, errno);
close(f);
return 1;
}
close(f);
+
while (secret[len - 1] == '\r' || secret[len - 1] == '\n') len--;
+ if (len > MAX_SECRET_SIZE)
+ {
+ my_printf_error(EE_READ,
+ "Cannot read %s, the filekey is too long, "
+ "max secret size is %dB ",
+ ME_ERROR_LOG, filekey, MAX_SECRET_SIZE);
+ return 1;
+ }
secret[len]= '\0';
return 0;
}