more strncpy fixes

This commit is contained in:
2018-07-03 18:03:55 +03:00
parent d0c654dc96
commit 43550b2c5a

View File

@@ -252,16 +252,16 @@ static int test_conf_syntax(void)
if (!strcmp(tmp + 1, "mysql")) { if (!strcmp(tmp + 1, "mysql")) {
/* || !strcmp(tmp[1], "postgresql") */ /* || !strcmp(tmp[1], "postgresql") */
/* || !strcmp(tmp[1], "oracle") */ /* || !strcmp(tmp[1], "oracle") */
strcpy(conf.db.type, tmp + 1); strncpy(conf.db.type, tmp + 1, sizeof(conf.db.type) - 1);
if (conf.db.port[0] == '\0') if (conf.db.port[0] == '\0')
strcpy(conf.db.port, "3306"); strncpy(conf.db.port, "3306", sizeof(conf.db.port) - 1);
} else { } else {
ok = 0; ok = 0;
failed = 1; failed = 1;
} }
} else if (!strcmp(buf, "db.hostname")) } else if (!strcmp(buf, "db.hostname"))
/* Just save it, launch_rmps will check it */ /* Just save it, launch_rmps will check it */
strcpy(conf.db.hostname, tmp + 1); strncpy(conf.db.hostname, tmp + 1, sizeof(conf.db.hostname) - 1);
else if (!strcmp(buf, "db.port")) { else if (!strcmp(buf, "db.port")) {
i = strlen(tmp + 1); i = strlen(tmp + 1);
if (i < 6) { /* max 5 digits for network port */ if (i < 6) { /* max 5 digits for network port */
@@ -269,7 +269,7 @@ static int test_conf_syntax(void)
"1234567890") == i) { "1234567890") == i) {
i = atoi(tmp + 1); i = atoi(tmp + 1);
if (i > 0 && i < 65536) { if (i > 0 && i < 65536) {
strcpy(conf.db.port, tmp + 1); strncpy(conf.db.port, tmp + 1, sizeof(conf.db.port) - 1);
continue; continue;
} }
} }
@@ -277,7 +277,7 @@ static int test_conf_syntax(void)
ok = 0; ok = 0;
failed = 1; failed = 1;
} else if (!strcmp(buf, "db.pass")) } else if (!strcmp(buf, "db.pass"))
strcpy(conf.db.pass, tmp + 1); strncpy(conf.db.pass, tmp + 1, sizeof(conf.db.pass) - 1);
else if (!strcmp(buf, "rmps.agent_ip")) { else if (!strcmp(buf, "rmps.agent_ip")) {
/* TODO */ /* TODO */
} else if (!strcmp(buf, "rmps.agent_port")) { } else if (!strcmp(buf, "rmps.agent_port")) {
@@ -287,8 +287,8 @@ static int test_conf_syntax(void)
"1234567890") == i) { "1234567890") == i) {
i = atoi(tmp + 1); i = atoi(tmp + 1);
if (i > 0 && i < 65536) { if (i > 0 && i < 65536) {
strcpy(conf.rmps.agent_port, strncpy(conf.rmps.agent_port,
tmp + 1); tmp + 1, sizeof(conf.rmps.agent_port) - 1);
continue; continue;
} }
} }
@@ -304,8 +304,8 @@ static int test_conf_syntax(void)
"1234567890") == i) { "1234567890") == i) {
i = atoi(tmp + 1); i = atoi(tmp + 1);
if (i > 0 && i < 65536) { if (i > 0 && i < 65536) {
strcpy(conf.rmps.client_port, strncpy(conf.rmps.client_port,
tmp + 1); tmp + 1, sizeof(conf.rmps.client_port) - 1);
continue; continue;
} }
} }
@@ -313,11 +313,11 @@ static int test_conf_syntax(void)
ok = 0; ok = 0;
failed = 1; failed = 1;
} else if (!strcmp(buf, "rmps.logfile")) { } else if (!strcmp(buf, "rmps.logfile")) {
strcpy(conf.rmps.logfile, tmp + 1); strncpy(conf.rmps.logfile, tmp + 1, sizeof(conf.rmps.logfile) - 1);
if (fopen_and_mkdir(conf.rmps.logfile) != 0) if (fopen_and_mkdir(conf.rmps.logfile) != 0)
failed = 1; failed = 1;
} else if (!strcmp(buf, "rmps.errlog")) { } else if (!strcmp(buf, "rmps.errlog")) {
strcpy(conf.rmps.errlog, tmp + 1); strncpy(conf.rmps.errlog, tmp + 1, sizeof(conf.rmps.errlog) - 1);
if (fopen_and_mkdir(conf.rmps.errlog) != 0) if (fopen_and_mkdir(conf.rmps.errlog) != 0)
failed = 1; failed = 1;
} else if (!strcmp(buf, "rmps.pidfile")) { } else if (!strcmp(buf, "rmps.pidfile")) {