From b42974a9e2d83e70c166cd572725a8d72bd2a1c4 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 11 Jun 2008 14:29:31 +0200 Subject: [PATCH] Replace all occurrences of `strcpy' with `sstrncpy'. --- src/apache.c | 12 ++++++------ src/apcups.c | 6 +++--- src/apple_sensors.c | 16 ++++++++-------- src/battery.c | 6 +++--- src/cpu.c | 6 +++--- src/cpufreq.c | 4 ++-- src/df.c | 6 +++--- src/disk.c | 4 ++-- src/dns.c | 8 ++++---- src/email.c | 4 ++-- src/entropy.c | 8 ++++---- src/hddtemp.c | 4 ++-- src/interface.c | 4 ++-- src/iptables.c | 4 ++-- src/ipvs.c | 16 ++++++++-------- src/irq.c | 4 ++-- src/load.c | 4 ++-- src/mbmon.c | 4 ++-- src/memcached.c | 16 ++++++++-------- src/memory.c | 4 ++-- src/multimeter.c | 4 ++-- src/mysql.c | 16 ++++++++-------- src/netlink.c | 8 ++++---- src/network.c | 10 +++++----- src/nfs.c | 4 ++-- src/nginx.c | 6 +++--- src/ntpd.c | 6 +++--- src/nut.c | 2 +- src/perl.c | 2 +- src/ping.c | 6 +++--- src/processes.c | 10 +++++----- src/rrdtool.c | 4 ++-- src/serial.c | 4 ++-- src/snmp.c | 4 ++-- src/swap.c | 4 ++-- src/tape.c | 4 ++-- src/tcpconns.c | 4 ++-- src/users.c | 4 ++-- src/utils_cmd_putval.c | 8 ++++---- src/utils_dns.c | 2 +- src/vserver.c | 12 ++++++------ src/wireless.c | 4 ++-- src/xmms.c | 4 ++-- 43 files changed, 136 insertions(+), 136 deletions(-) diff --git a/src/apache.c b/src/apache.c index 2a7e0b80..54a5d562 100644 --- a/src/apache.c +++ b/src/apache.c @@ -173,9 +173,9 @@ static void submit_counter (const char *type, const char *type_instance, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "apache"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "apache", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); if (type_instance != NULL) { @@ -198,9 +198,9 @@ static void submit_gauge (const char *type, const char *type_instance, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "apache"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "apache", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); if (type_instance != NULL) { diff --git a/src/apcups.c b/src/apcups.c index 5a03764f..c948f5a1 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -373,9 +373,9 @@ static void apc_submit_generic (char *type, char *type_inst, double value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "apcups"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "apcups", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); plugin_dispatch_values (type, &vl); diff --git a/src/apple_sensors.c b/src/apple_sensors.c index 2726ad2e..5e957b6f 100644 --- a/src/apple_sensors.c +++ b/src/apple_sensors.c @@ -88,10 +88,10 @@ static void as_submit (const char *type, const char *type_instance, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "apple_sensors"); - strcpy (vl.plugin_instance, ""); - strcpy (vl.type_instance, type_instance); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "apple_sensors", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (type, &vl); } @@ -192,17 +192,17 @@ static int as_read (void) if (strcmp (type, "temperature") == 0) { value_double = ((double) value_int) / 65536.0; - strcpy (type, "temperature"); + sstrncpy (type, "temperature", sizeof (type)); } else if (strcmp (type, "temp") == 0) { value_double = ((double) value_int) / 10.0; - strcpy (type, "temperature"); + sstrncpy (type, "temperature", sizeof (type)); } else if (strcmp (type, "fanspeed") == 0) { value_double = ((double) value_int) / 65536.0; - strcpy (type, "fanspeed"); + sstrncpy (type, "fanspeed", sizeof (type)); } else if (strcmp (type, "voltage") == 0) { @@ -212,7 +212,7 @@ static int as_read (void) else if (strcmp (type, "adc") == 0) { value_double = ((double) value_int) / 10.0; - strcpy (type, "fanspeed"); + sstrncpy (type, "fanspeed", sizeof (type)); } else { diff --git a/src/battery.c b/src/battery.c index 345f606e..badd8e75 100644 --- a/src/battery.c +++ b/src/battery.c @@ -98,9 +98,9 @@ static void battery_submit (const char *plugin_instance, const char *type, doubl vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "battery"); - strcpy (vl.plugin_instance, plugin_instance); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "battery", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); plugin_dispatch_values (type, &vl); } /* void battery_submit */ diff --git a/src/cpu.c b/src/cpu.c index c79c4b66..0daebcc0 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -167,12 +167,12 @@ static void submit (int cpu_num, const char *type_instance, counter_t value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "cpu"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "cpu", sizeof (vl.plugin)); snprintf (vl.plugin_instance, sizeof (vl.type_instance), "%i", cpu_num); vl.plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0'; - strcpy (vl.type_instance, type_instance); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values ("cpu", &vl); } diff --git a/src/cpufreq.c b/src/cpufreq.c index 42248a98..74e542b4 100644 --- a/src/cpufreq.c +++ b/src/cpufreq.c @@ -68,8 +68,8 @@ static void cpufreq_submit (int cpu_num, double value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "cpufreq"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "cpufreq", sizeof (vl.plugin)); snprintf (vl.type_instance, sizeof (vl.type_instance), "%i", cpu_num); diff --git a/src/df.c b/src/df.c index 0f357d8d..6bd92500 100644 --- a/src/df.c +++ b/src/df.c @@ -125,9 +125,9 @@ static void df_submit (char *df_name, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "df"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "df", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); strncpy (vl.type_instance, df_name, sizeof (vl.type_instance)); plugin_dispatch_values ("df", &vl); diff --git a/src/disk.c b/src/disk.c index e7372ab7..536c5111 100644 --- a/src/disk.c +++ b/src/disk.c @@ -164,8 +164,8 @@ static void disk_submit (const char *plugin_instance, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "disk"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "disk", sizeof (vl.plugin)); strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); diff --git a/src/dns.c b/src/dns.c index e9996b99..69cb1922 100644 --- a/src/dns.c +++ b/src/dns.c @@ -299,8 +299,8 @@ static void submit_counter (const char *type, const char *type_instance, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "dns"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "dns", sizeof (vl.plugin)); strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (type, &vl); @@ -317,8 +317,8 @@ static void submit_octets (counter_t queries, counter_t responses) vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "dns"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "dns", sizeof (vl.plugin)); plugin_dispatch_values ("dns_octets", &vl); } /* void submit_counter */ diff --git a/src/email.c b/src/email.c index 869b7c36..b718cf5c 100644 --- a/src/email.c +++ b/src/email.c @@ -733,8 +733,8 @@ static void email_submit (const char *type, const char *type_instance, gauge_t v vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "email"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "email", sizeof (vl.plugin)); strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (type, &vl); diff --git a/src/entropy.c b/src/entropy.c index 5f9eb530..69ce3142 100644 --- a/src/entropy.c +++ b/src/entropy.c @@ -39,10 +39,10 @@ static void entropy_submit (double entropy) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "entropy"); - strcpy (vl.plugin_instance, ""); - strcpy (vl.type_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "entropy", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); + sstrncpy (vl.type_instance, "", sizeof (vl.type_instance)); plugin_dispatch_values ("entropy", &vl); } diff --git a/src/hddtemp.c b/src/hddtemp.c index 36ada53c..cb495770 100644 --- a/src/hddtemp.c +++ b/src/hddtemp.c @@ -449,8 +449,8 @@ static void hddtemp_submit (char *type_instance, double value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "hddtemp"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "hddtemp", sizeof (vl.plugin)); strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values ("temperature", &vl); diff --git a/src/interface.c b/src/interface.c index 33736b67..2add89d7 100644 --- a/src/interface.c +++ b/src/interface.c @@ -197,8 +197,8 @@ static void if_submit (const char *dev, const char *type, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "interface"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "interface", sizeof (vl.plugin)); strncpy (vl.type_instance, dev, sizeof (vl.type_instance)); plugin_dispatch_values (type, &vl); diff --git a/src/iptables.c b/src/iptables.c index 72b4481c..6522a559 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -219,8 +219,8 @@ static int submit_match (const struct ipt_entry_match *match, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "iptables"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "iptables", sizeof (vl.plugin)); status = snprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%s-%s", chain->table, chain->chain); diff --git a/src/ipvs.c b/src/ipvs.c index 68a3d7f3..31e97415 100644 --- a/src/ipvs.c +++ b/src/ipvs.c @@ -238,10 +238,10 @@ static void cipvs_submit_connections (char *pi, char *ti, counter_t value) vl.time = time (NULL); vl.interval = interval_g; - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "ipvs"); - strcpy (vl.plugin_instance, pi); - strcpy (vl.type_instance, (NULL != ti) ? ti : "total"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "ipvs", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance)); + sstrncpy (vl.type_instance, (NULL != ti) ? ti : "total", sizeof (vl.type_instance)); plugin_dispatch_values ("connections", &vl); return; @@ -262,10 +262,10 @@ static void cipvs_submit_if (char *pi, char *t, char *ti, vl.time = time (NULL); vl.interval = interval_g; - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "ipvs"); - strcpy (vl.plugin_instance, pi); - strcpy (vl.type_instance, (NULL != ti) ? ti : "total"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "ipvs", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance)); + sstrncpy (vl.type_instance, (NULL != ti) ? ti : "total", sizeof (vl.type_instance)); plugin_dispatch_values (t, &vl); return; diff --git a/src/irq.c b/src/irq.c index 9eb1de42..93c6076b 100644 --- a/src/irq.c +++ b/src/irq.c @@ -132,8 +132,8 @@ static void irq_submit (unsigned int irq, counter_t value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "irq"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "irq", sizeof (vl.plugin)); status = snprintf (vl.type_instance, sizeof (vl.type_instance), "%u", irq); diff --git a/src/load.c b/src/load.c index 15215d3c..e0e0c0ed 100644 --- a/src/load.c +++ b/src/load.c @@ -51,8 +51,8 @@ static void load_submit (gauge_t snum, gauge_t mnum, gauge_t lnum) vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "load"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "load", sizeof (vl.plugin)); plugin_dispatch_values ("load", &vl); } diff --git a/src/mbmon.c b/src/mbmon.c index 50d73632..22a26da5 100644 --- a/src/mbmon.c +++ b/src/mbmon.c @@ -228,8 +228,8 @@ static void mbmon_submit (const char *type, const char *type_instance, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "mbmon"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "mbmon", sizeof (vl.plugin)); strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (type, &vl); diff --git a/src/memcached.c b/src/memcached.c index a1825780..c830598d 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -224,8 +224,8 @@ static void submit_counter (const char *type, const char *type_inst, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "memcached"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); if (type_inst != NULL) { strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); @@ -248,8 +248,8 @@ static void submit_counter2 (const char *type, const char *type_inst, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "memcached"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); if (type_inst != NULL) { strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); @@ -271,8 +271,8 @@ static void submit_gauge (const char *type, const char *type_inst, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "memcached"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); if (type_inst != NULL) { strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); @@ -295,8 +295,8 @@ static void submit_gauge2 (const char *type, const char *type_inst, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "memcached"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin)); if (type_inst != NULL) { strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); diff --git a/src/memory.c b/src/memory.c index fe3a16eb..583f71a2 100644 --- a/src/memory.c +++ b/src/memory.c @@ -109,8 +109,8 @@ static void memory_submit (const char *type_instance, gauge_t value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "memory"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "memory", sizeof (vl.plugin)); strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; diff --git a/src/multimeter.c b/src/multimeter.c index 11ca42c1..c6b070a0 100644 --- a/src/multimeter.c +++ b/src/multimeter.c @@ -216,8 +216,8 @@ static void multimeter_submit (double value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "multimeter"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "multimeter", sizeof (vl.plugin)); plugin_dispatch_values ("multimeter", &vl); } diff --git a/src/mysql.c b/src/mysql.c index d4728531..aa585d65 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -126,8 +126,8 @@ static void counter_submit (const char *type, const char *type_instance, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "mysql"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin)); strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (type, &vl); @@ -149,8 +149,8 @@ static void qcache_submit (counter_t hits, counter_t inserts, vl.values = values; vl.values_len = 5; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "mysql"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin)); plugin_dispatch_values ("mysql_qcache", &vl); } /* void qcache_submit */ @@ -169,8 +169,8 @@ static void threads_submit (gauge_t running, gauge_t connected, gauge_t cached, vl.values = values; vl.values_len = 4; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "mysql"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin)); plugin_dispatch_values ("mysql_threads", &vl); } /* void threads_submit */ @@ -186,8 +186,8 @@ static void traffic_submit (counter_t rx, counter_t tx) vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "mysql"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin)); plugin_dispatch_values ("mysql_octets", &vl); } /* void traffic_submit */ diff --git a/src/netlink.c b/src/netlink.c index 22afdc77..e54365d0 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -171,8 +171,8 @@ static void submit_one (const char *dev, const char *type, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "netlink"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "netlink", sizeof (vl.plugin)); strncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); if (type_instance != NULL) @@ -194,8 +194,8 @@ static void submit_two (const char *dev, const char *type, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "netlink"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "netlink", sizeof (vl.plugin)); strncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); if (type_instance != NULL) diff --git a/src/network.c b/src/network.c index ff806af3..022e46a1 100644 --- a/src/network.c +++ b/src/network.c @@ -1405,7 +1405,7 @@ static int add_to_buffer (char *buffer, int buffer_size, if (write_part_string (&buffer, &buffer_size, TYPE_HOST, vl->host, strlen (vl->host)) != 0) return (-1); - strcpy (vl_def->host, vl->host); + sstrncpy (vl_def->host, vl->host, sizeof (vl_def->host)); } if (vl_def->time != vl->time) @@ -1429,7 +1429,7 @@ static int add_to_buffer (char *buffer, int buffer_size, if (write_part_string (&buffer, &buffer_size, TYPE_PLUGIN, vl->plugin, strlen (vl->plugin)) != 0) return (-1); - strcpy (vl_def->plugin, vl->plugin); + sstrncpy (vl_def->plugin, vl->plugin, sizeof (vl_def->plugin)); } if (strcmp (vl_def->plugin_instance, vl->plugin_instance) != 0) @@ -1438,7 +1438,7 @@ static int add_to_buffer (char *buffer, int buffer_size, vl->plugin_instance, strlen (vl->plugin_instance)) != 0) return (-1); - strcpy (vl_def->plugin_instance, vl->plugin_instance); + sstrncpy (vl_def->plugin_instance, vl->plugin_instance, sizeof (vl_def->plugin_instance)); } if (strcmp (type_def, ds->type) != 0) @@ -1446,7 +1446,7 @@ static int add_to_buffer (char *buffer, int buffer_size, if (write_part_string (&buffer, &buffer_size, TYPE_TYPE, ds->type, strlen (ds->type)) != 0) return (-1); - strcpy (type_def, ds->type); + sstrncpy (type_def, ds->type, sizeof (type_def)); } if (strcmp (vl_def->type_instance, vl->type_instance) != 0) @@ -1455,7 +1455,7 @@ static int add_to_buffer (char *buffer, int buffer_size, vl->type_instance, strlen (vl->type_instance)) != 0) return (-1); - strcpy (vl_def->type_instance, vl->type_instance); + sstrncpy (vl_def->type_instance, vl->type_instance, sizeof (vl_def->type_instance)); } if (write_part_values (&buffer, &buffer_size, ds, vl) != 0) diff --git a/src/nfs.c b/src/nfs.c index 77c7f48f..91e67886 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -188,8 +188,8 @@ static void nfs_procedures_submit (const char *plugin_instance, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "nfs"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "nfs", sizeof (vl.plugin)); strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); diff --git a/src/nginx.c b/src/nginx.c index 0e3b843d..a5201a02 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -151,9 +151,9 @@ static void submit (char *type, char *inst, long long value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "nginx"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "nginx", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); if (inst != NULL) { diff --git a/src/ntpd.c b/src/ntpd.c index 90fdfd7c..ff0a48dc 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -302,9 +302,9 @@ static void ntpd_submit (char *type, char *type_inst, double value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "ntpd"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "ntpd", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); plugin_dispatch_values (type, &vl); diff --git a/src/nut.c b/src/nut.c index f7f026a6..695d93b5 100644 --- a/src/nut.c +++ b/src/nut.c @@ -129,7 +129,7 @@ static void nut_submit (nut_ups_t *ups, const char *type, ? hostname_g : ups->hostname, sizeof (vl.host)); - strcpy (vl.plugin, "nut"); + sstrncpy (vl.plugin, "nut", sizeof (vl.plugin)); strncpy (vl.plugin_instance, ups->upsname, sizeof (vl.plugin_instance)); strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); diff --git a/src/perl.c b/src/perl.c index 877bc008..22a13cee 100644 --- a/src/perl.c +++ b/src/perl.c @@ -553,7 +553,7 @@ static int pplugin_dispatch_values (pTHX_ char *name, HV *values) list.host[DATA_MAX_NAME_LEN - 1] = '\0'; } else { - strcpy (list.host, hostname_g); + sstrncpy (list.host, hostname_g, sizeof (list.host)); } if (NULL != (tmp = hv_fetch (values, "plugin", 6, 0))) { diff --git a/src/ping.c b/src/ping.c index 2f7c064d..09de77ce 100644 --- a/src/ping.c +++ b/src/ping.c @@ -186,9 +186,9 @@ static void ping_submit (char *host, double latency) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "ping"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "ping", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); strncpy (vl.type_instance, host, sizeof (vl.type_instance)); plugin_dispatch_values ("ping", &vl); diff --git a/src/processes.c b/src/processes.c index 22d369df..6ad46813 100644 --- a/src/processes.c +++ b/src/processes.c @@ -409,9 +409,9 @@ static void ps_submit_state (const char *state, double value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "processes"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "processes", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); strncpy (vl.type_instance, state, sizeof (vl.type_instance)); plugin_dispatch_values ("ps_state", &vl); @@ -425,8 +425,8 @@ static void ps_submit_proc_list (procstat_t *ps) vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "processes"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "processes", sizeof (vl.plugin)); strncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance)); vl.values[0].gauge = ps->vmem_rss; diff --git a/src/rrdtool.c b/src/rrdtool.c index 3bb5a9e7..adf6eeb1 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -285,7 +285,7 @@ static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl) if (isnan (d->min)) { - strcpy (min, "U"); + sstrncpy (min, "U", sizeof (min)); } else { @@ -295,7 +295,7 @@ static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl) if (isnan (d->max)) { - strcpy (max, "U"); + sstrncpy (max, "U", sizeof (max)); } else { diff --git a/src/serial.c b/src/serial.c index 9cfe1dd4..4f08a346 100644 --- a/src/serial.c +++ b/src/serial.c @@ -41,8 +41,8 @@ static void serial_submit (const char *type_instance, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "serial"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "serial", sizeof (vl.plugin)); strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); diff --git a/src/snmp.c b/src/snmp.c index 4311ff16..6788ea9b 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -909,7 +909,7 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat strncpy (vl.host, host->name, sizeof (vl.host)); vl.host[sizeof (vl.host) - 1] = '\0'; - strcpy (vl.plugin, "snmp"); + sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin)); vl.interval = host->interval; vl.time = time (NULL); @@ -1301,7 +1301,7 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) strncpy (vl.host, host->name, sizeof (vl.host)); vl.host[sizeof (vl.host) - 1] = '\0'; - strcpy (vl.plugin, "snmp"); + sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin)); strncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance)); vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; diff --git a/src/swap.c b/src/swap.c index e91ebefd..4d1f24de 100644 --- a/src/swap.c +++ b/src/swap.c @@ -124,8 +124,8 @@ static void swap_submit (const char *type_instance, double value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "swap"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "swap", sizeof (vl.plugin)); strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values ("swap", &vl); diff --git a/src/tape.c b/src/tape.c index 465688ed..5b5cdb46 100644 --- a/src/tape.c +++ b/src/tape.c @@ -69,8 +69,8 @@ static void tape_submit (const char *plugin_instance, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "tape"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "tape", sizeof (vl.plugin)); strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); diff --git a/src/tcpconns.c b/src/tcpconns.c index fdf7ec1b..5a8f4619 100644 --- a/src/tcpconns.c +++ b/src/tcpconns.c @@ -135,8 +135,8 @@ static void conn_submit_port_entry (port_entry_t *pe) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "tcpconns"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "tcpconns", sizeof (vl.plugin)); if (((port_collect_listening != 0) && (pe->flags & PORT_IS_LISTENING)) || (pe->flags & PORT_COLLECT_LOCAL)) diff --git a/src/users.c b/src/users.c index afe26e1e..5e6a0b5a 100644 --- a/src/users.c +++ b/src/users.c @@ -45,8 +45,8 @@ static void users_submit (gauge_t value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "users"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "users", sizeof (vl.plugin)); plugin_dispatch_values ("users", &vl); } /* void users_submit */ diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c index 98b5043f..e5f74950 100644 --- a/src/utils_cmd_putval.c +++ b/src/utils_cmd_putval.c @@ -166,12 +166,12 @@ int handle_putval (FILE *fh, char **fields, int fields_num) return (-1); } - strcpy (vl.host, hostname); - strcpy (vl.plugin, plugin); + sstrncpy (vl.host, hostname, sizeof (vl.host)); + sstrncpy (vl.plugin, plugin, sizeof (vl.plugin)); if (plugin_instance != NULL) - strcpy (vl.plugin_instance, plugin_instance); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); if (type_instance != NULL) - strcpy (vl.type_instance, type_instance); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); ds = plugin_get_ds (type); if (ds == NULL) { diff --git a/src/utils_dns.c b/src/utils_dns.c index 25ef1899..3f5d4fb2 100644 --- a/src/utils_dns.c +++ b/src/utils_dns.c @@ -384,7 +384,7 @@ handle_dns(const char *buf, int len, if (0 != x) return 0; if ('\0' == qh.qname[0]) - strcpy(qh.qname, "."); + strncpy (qh.qname, ".", sizeof (qh.qname)); while ((t = strchr(qh.qname, '\n'))) *t = ' '; while ((t = strchr(qh.qname, '\r'))) diff --git a/src/vserver.c b/src/vserver.c index 7b83c617..54843449 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -57,8 +57,8 @@ static void traffic_submit (const char *plugin_instance, vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "vserver"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin)); strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); @@ -78,8 +78,8 @@ static void load_submit (const char *plugin_instance, vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "vserver"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin)); strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); plugin_dispatch_values ("load", &vl); @@ -97,8 +97,8 @@ static void submit_gauge (const char *plugin_instance, const char *type, vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "vserver"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin)); strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); diff --git a/src/wireless.c b/src/wireless.c index fdea9d3b..0edaf458 100644 --- a/src/wireless.c +++ b/src/wireless.c @@ -56,8 +56,8 @@ static void wireless_submit (const char *plugin_instance, const char *type, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "wireless"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "wireless", sizeof (vl.plugin)); strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); diff --git a/src/xmms.c b/src/xmms.c index 1e646d21..7f3edf0a 100644 --- a/src/xmms.c +++ b/src/xmms.c @@ -37,8 +37,8 @@ static void cxmms_submit (const char *type, gauge_t value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "xmms"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "xmms", sizeof (vl.plugin)); plugin_dispatch_values (type, &vl); } /* void cxmms_submit */ -- 2.11.0