Fix format-overflow warnings in tests

The tests previously ignored these warnings but the change in compiler
flags caused them to fail.
This commit is contained in:
Markus Mäkelä
2019-02-18 09:03:07 +02:00
parent 2045ac656b
commit a6ab05b673
5 changed files with 45 additions and 39 deletions

View File

@ -66,7 +66,7 @@ int main(int argc, char* argv[])
{ {
TestConnections* Test = new TestConnections(argc, argv); TestConnections* Test = new TestConnections(argc, argv);
Test->set_timeout(30); Test->set_timeout(30);
char str[1024]; char str[4096 + 1024];
sprintf(str, sprintf(str,
"php %s/bug729.php %s %d %s %s", "php %s/bug729.php %s %d %s %s",

View File

@ -5,7 +5,7 @@
#define FAILOVER_WAIT_TIME 20 #define FAILOVER_WAIT_TIME 20
char virtual_ip[16]; char virtual_ip[27];
char* print_version_string(TestConnections* Test); char* print_version_string(TestConnections* Test);
void configure_keepalived(TestConnections* Test, char* keepalived_file); void configure_keepalived(TestConnections* Test, char* keepalived_file);
void stop_keepalived(TestConnections* Test); void stop_keepalived(TestConnections* Test);

View File

@ -321,7 +321,7 @@ int Mariadb_nodes::stop_node(int node)
int Mariadb_nodes::start_node(int node, const char* param) int Mariadb_nodes::start_node(int node, const char* param)
{ {
char cmd[1024]; char cmd[PATH_MAX + 1024];
if (v51) if (v51)
{ {
sprintf(cmd, "%s %s --report-host", start_db_command[node], param); sprintf(cmd, "%s %s --report-host", start_db_command[node], param);
@ -391,8 +391,8 @@ int Mariadb_nodes::cleanup_db_nodes()
void Mariadb_nodes::create_users(int node) void Mariadb_nodes::create_users(int node)
{ {
char str[1024]; char str[PATH_MAX + 1024];
char dtr[1024]; char dtr[PATH_MAX + 1024];
// Create users for replication as well as the users that are used by the tests // Create users for replication as well as the users that are used by the tests
sprintf(str, "%s/create_user.sh", test_dir); sprintf(str, "%s/create_user.sh", test_dir);
sprintf(dtr, "%s", access_homedir[node]); sprintf(dtr, "%s", access_homedir[node]);
@ -502,11 +502,13 @@ int Galera_nodes::start_galera()
} }
} }
char str[1024]; char str[PATH_MAX + 1024];
sprintf(str, "%s/create_user_galera.sh", test_dir); sprintf(str, "%s/create_user_galera.sh", test_dir);
copy_to_node_legacy(str, "~/", 0); copy_to_node_legacy(str, "~/", 0);
ssh_node_f(0, false, "export galera_user=\"%s\"; export galera_password=\"%s\"; ./create_user_galera.sh %s", ssh_node_f(0,
false,
"export galera_user=\"%s\"; export galera_password=\"%s\"; ./create_user_galera.sh %s",
user_name, user_name,
password, password,
socket_cmd[0]); socket_cmd[0]);
@ -521,10 +523,12 @@ int Galera_nodes::start_galera()
int Mariadb_nodes::clean_iptables(int node) int Mariadb_nodes::clean_iptables(int node)
{ {
return ssh_node_f(node, true, return ssh_node_f(node,
true,
"while [ \"$(iptables -n -L INPUT 1|grep '%d')\" != \"\" ]; do iptables -D INPUT 1; done;" "while [ \"$(iptables -n -L INPUT 1|grep '%d')\" != \"\" ]; do iptables -D INPUT 1; done;"
"while [ \"$(ip6tables -n -L INPUT 1|grep '%d')\" != \"\" ]; do ip6tables -D INPUT 1; done;", "while [ \"$(ip6tables -n -L INPUT 1|grep '%d')\" != \"\" ]; do ip6tables -D INPUT 1; done;",
port[node], port[node]); port[node],
port[node]);
} }
int Mariadb_nodes::block_node(int node) int Mariadb_nodes::block_node(int node)
@ -1057,7 +1061,8 @@ int Mariadb_nodes::get_version(int i)
int local_result = 0; int local_result = 0;
if (find_field(nodes[i], "SELECT @@version", "@@version", version[i])) if (find_field(nodes[i], "SELECT @@version", "@@version", version[i]))
{ {
cout << "Failed to get version: " << mysql_error(nodes[i]) << ", trying ssh node and use MariaDB client" << endl; cout << "Failed to get version: " << mysql_error(nodes[i])
<< ", trying ssh node and use MariaDB client" << endl;
str = ssh_node_output(i, "mysql --batch --silent -e \"select @@version\"", true, &ec); str = ssh_node_output(i, "mysql --batch --silent -e \"select @@version\"", true, &ec);
if (ec) if (ec)
{ {
@ -1141,10 +1146,11 @@ int Mariadb_nodes::truncate_mariadb_logs()
int local_result = 0; int local_result = 0;
for (int node = 0; node < N; node++) for (int node = 0; node < N; node++)
{ {
char sys[1024]; char sys[PATH_MAX + 1500];
if (strcmp(IP[node], "127.0.0.1") != 0) if (strcmp(IP[node], "127.0.0.1") != 0)
{ {
sprintf(sys, snprintf(sys,
sizeof(sys),
"ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s 'sudo truncate /var/lib/mysql/*.err --size 0;sudo rm -f /etc/my.cnf.d/binlog_enc*\' &", "ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s 'sudo truncate /var/lib/mysql/*.err --size 0;sudo rm -f /etc/my.cnf.d/binlog_enc*\' &",
sshkey[node], sshkey[node],
access_user[node], access_user[node],
@ -1158,7 +1164,7 @@ int Mariadb_nodes::truncate_mariadb_logs()
int Mariadb_nodes::configure_ssl(bool require) int Mariadb_nodes::configure_ssl(bool require)
{ {
int local_result = 0; int local_result = 0;
char str[1024]; char str[PATH_MAX + 256];
this->ssl = 1; this->ssl = 1;

View File

@ -199,7 +199,7 @@ int main(int argc, char* argv[])
fclose(f); fclose(f);
Test->tprintf("Copying expected script output to Maxscale machine"); Test->tprintf("Copying expected script output to Maxscale machine");
char str[2048]; char str[4096 + 2048];
sprintf(str, sprintf(str,
"scp -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet script_output_expected* %s@%s:%s/", "scp -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet script_output_expected* %s@%s:%s/",
Test->maxscales->sshkey[0], Test->maxscales->sshkey[0],

View File

@ -659,7 +659,7 @@ void TestConnections::process_template(int m, const char* template_name, const c
char str[4096]; char str[4096];
char template_file[1024]; char template_file[1024];
char extended_template_file[1024]; char extended_template_file[1024 + 12];
sprintf(template_file, "%s/cnf/maxscale.cnf.template.%s", test_dir, template_name); sprintf(template_file, "%s/cnf/maxscale.cnf.template.%s", test_dir, template_name);
sprintf(extended_template_file, "%s.%03d", template_file, m); sprintf(extended_template_file, "%s.%03d", template_file, m);
@ -853,9 +853,9 @@ int TestConnections::copy_all_logs()
} }
int TestConnections::copy_maxscale_logs(double timestamp) int TestConnections::copy_maxscale_logs(double timestamp)
{ {
char log_dir[1024]; char log_dir[PATH_MAX + 1024];
char log_dir_i[1024]; char log_dir_i[sizeof(log_dir) + 1024];
char sys[1024]; char sys[sizeof(log_dir_i) + 1024];
if (timestamp == 0) if (timestamp == 0)
{ {
sprintf(log_dir, "LOGS/%s", test_name); sprintf(log_dir, "LOGS/%s", test_name);
@ -2055,14 +2055,14 @@ void TestConnections::check_current_connections(int m, int value)
int TestConnections::take_snapshot(char* snapshot_name) int TestConnections::take_snapshot(char* snapshot_name)
{ {
char str[4096]; char str[PATH_MAX + 4096];
sprintf(str, "%s %s", take_snapshot_command, snapshot_name); sprintf(str, "%s %s", take_snapshot_command, snapshot_name);
return call_system(str); return call_system(str);
} }
int TestConnections::revert_snapshot(char* snapshot_name) int TestConnections::revert_snapshot(char* snapshot_name)
{ {
char str[4096]; char str[PATH_MAX + 4096];
sprintf(str, "%s %s", revert_snapshot_command, snapshot_name); sprintf(str, "%s %s", revert_snapshot_command, snapshot_name);
return call_system(str); return call_system(str);
} }