Skip to content

Commit 6e708a1

Browse files
committed
[#3256] convert mysql_ssl_set to mysql_options
1 parent 0fcf61e commit 6e708a1

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/lib/mysql/mysql_connection.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,12 @@ MySqlConnection::openDatabase() {
237237
// If TLS is enabled set it. If something should go wrong it will happen
238238
// later at the mysql_real_connect call.
239239
if (tls_) {
240-
mysql_ssl_set(mysql_, key_file, cert_file, ca_file, ca_dir,
241-
cipher_list);
240+
mysql_options(mysql_, MYSQL_OPT_SSL_KEY, key_file);
241+
mysql_options(mysql_, MYSQL_OPT_SSL_CERT, cert_file);
242+
mysql_options(mysql_, MYSQL_OPT_SSL_CA, ca_file);
243+
mysql_options(mysql_, MYSQL_OPT_SSL_CAPATH, ca_dir);
244+
mysql_options(mysql_, MYSQL_OPT_SSL_CIPHER, cipher_list);
245+
242246
}
243247

244248
// Open the database.

src/lib/mysql/tests/mysql_connection_unittest.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,4 +1008,19 @@ TEST_F(MySqlConnectionTest, toKeaAdminParameters) {
10081008
"--ssl-ca " TEST_CA_DIR "/kea-ca.crt", "--user", "keatest_secure"}));
10091009
}
10101010

1011+
/// @brief Checks that the mysql_options call does not crash when passed a null option value.
1012+
///
1013+
/// An unconventional test, but the MySQL docs are not clear:
1014+
/// > Any unused SSL arguments may be given as NULL.
1015+
/// > Because of that equivalence, applications can, instead of calling mysql_ssl_set(), call
1016+
/// mysql_options() directly, omitting calls for those options for which the option value is NULL.
1017+
TEST_F(MySqlConnectionTest, mysqlOptions) {
1018+
MySqlHolder mysql;
1019+
mysql_options(mysql, MYSQL_OPT_SSL_KEY, nullptr);
1020+
mysql_options(mysql, MYSQL_OPT_SSL_CERT, nullptr);
1021+
mysql_options(mysql, MYSQL_OPT_SSL_CA, nullptr);
1022+
mysql_options(mysql, MYSQL_OPT_SSL_CAPATH, nullptr);
1023+
mysql_options(mysql, MYSQL_OPT_SSL_CIPHER, nullptr);
1024+
}
1025+
10111026
} // namespace

0 commit comments

Comments
 (0)