From: Sebastian Harl Date: Sun, 20 Apr 2008 21:20:45 +0000 (+0200) Subject: Unified string handling. X-Git-Tag: collectd-4.5.0~162 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5f9ec13b;p=collectd.git Unified string handling. sstrncpy() and the newly added function ssnprintf() are now used all over the place to make sure strings are null terminated. This removes quite some duplicate code that was found all over the place and thus fairly increases overall readability of the code. Also sizeof() is used instead of hard-coded constants where appropriate to determine the available space. Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- diff --git a/src/apache.c b/src/apache.c index 55d8cd47..7667f247 100644 --- a/src/apache.c +++ b/src/apache.c @@ -146,7 +146,7 @@ static int init (void) { int status; - status = snprintf (credentials, sizeof (credentials), "%s:%s", + status = ssnprintf (credentials, sizeof (credentials), "%s:%s", user, (pass == NULL) ? "" : pass); if (status >= sizeof (credentials)) { @@ -155,7 +155,6 @@ static int init (void) "truncated."); return (-1); } - credentials[sizeof (credentials) - 1] = '\0'; curl_easy_setopt (curl, CURLOPT_USERPWD, credentials); } @@ -202,14 +201,11 @@ static void submit_counter (const char *type, const char *type_instance, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "apache"); strcpy (vl.plugin_instance, ""); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) - { - strncpy (vl.type_instance, type_instance, + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } plugin_dispatch_values (&vl); } /* void submit_counter */ @@ -228,14 +224,11 @@ static void submit_gauge (const char *type, const char *type_instance, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "apache"); strcpy (vl.plugin_instance, ""); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) - { - strncpy (vl.type_instance, type_instance, + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } plugin_dispatch_values (&vl); } /* void submit_counter */ diff --git a/src/apcups.c b/src/apcups.c index 7f8afd46..fb481092 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -124,8 +124,7 @@ static int net_open (char *host, int port) assert ((port > 0x00000000) && (port <= 0x0000FFFF)); /* Convert the port to a string */ - snprintf (port_str, 8, "%i", port); - port_str[7] = '\0'; + ssnprintf (port_str, sizeof (port_str), "%i", port); /* Resolve name */ memset ((void *) &ai_hints, '\0', sizeof (ai_hints)); @@ -376,8 +375,8 @@ static void apc_submit_generic (char *type, char *type_inst, double value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "apcups"); strcpy (vl.plugin_instance, ""); - strncpy (vl.type, type, sizeof (vl.type)); - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } diff --git a/src/apple_sensors.c b/src/apple_sensors.c index 5db6e9c5..ee0bf8c0 100644 --- a/src/apple_sensors.c +++ b/src/apple_sensors.c @@ -91,8 +91,8 @@ static void as_submit (const char *type, const char *type_instance, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "apple_sensors"); strcpy (vl.plugin_instance, ""); - strncpy (vl.type, type, sizeof (vl.type)) - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)) + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } @@ -147,10 +147,10 @@ static int as_read (void) if (CFGetTypeID (property) != CFStringGetTypeID ()) continue; if (!CFStringGetCString (property, - type, 128, + type, sizeof (type), kCFStringEncodingASCII)) continue; - type[127] = '\0'; + type[sizeof (type) - 1] = '\0'; /* Copy the sensor location. This will be used as `instance'. */ property = NULL; @@ -161,10 +161,10 @@ static int as_read (void) if (CFGetTypeID (property) != CFStringGetTypeID ()) continue; if (!CFStringGetCString (property, - inst, 128, + inst, sizeof (inst), kCFStringEncodingASCII)) continue; - inst[127] = '\0'; + inst[sizeof (inst) - 1] = '\0'; for (i = 0; i < 128; i++) { if (inst[i] == '\0') diff --git a/src/ascent.c b/src/ascent.c index e8ac0c20..6b4f21fc 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -536,7 +536,7 @@ static int ascent_init (void) /* {{{ */ { int status; - status = snprintf (credentials, sizeof (credentials), "%s:%s", + status = ssnprintf (credentials, sizeof (credentials), "%s:%s", user, (pass == NULL) ? "" : pass); if (status >= sizeof (credentials)) { @@ -544,7 +544,6 @@ static int ascent_init (void) /* {{{ */ "credentials have been truncated."); return (-1); } - credentials[sizeof (credentials) - 1] = '\0'; curl_easy_setopt (curl, CURLOPT_USERPWD, credentials); } diff --git a/src/battery.c b/src/battery.c index 05220152..f8e67a41 100644 --- a/src/battery.c +++ b/src/battery.c @@ -75,7 +75,7 @@ static int battery_init (void) for (battery_pmu_num = 0; ; battery_pmu_num++) { - len = snprintf (filename, sizeof (filename), battery_pmu_file, battery_pmu_num); + len = ssnprintf (filename, sizeof (filename), battery_pmu_file, battery_pmu_num); if ((len < 0) || ((unsigned int)len >= sizeof (filename))) break; @@ -100,8 +100,8 @@ static void battery_submit (const char *plugin_instance, const char *type, doubl vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "battery"); - strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); plugin_dispatch_values (&vl); } /* void battery_submit */ @@ -360,11 +360,11 @@ static int battery_read (void) double charge = INVALID_VALUE; double *valptr = NULL; - len = snprintf (filename, sizeof (filename), battery_pmu_file, i); + len = ssnprintf (filename, sizeof (filename), battery_pmu_file, i); if ((len < 0) || ((unsigned int)len >= sizeof (filename))) continue; - len = snprintf (batnum_str, sizeof (batnum_str), "%i", i); + len = ssnprintf (batnum_str, sizeof (batnum_str), "%i", i); if ((len < 0) || ((unsigned int)len >= sizeof (batnum_str))) continue; @@ -436,7 +436,7 @@ static int battery_read (void) if (ent->d_name[0] == '.') continue; - len = snprintf (filename, sizeof (filename), + len = ssnprintf (filename, sizeof (filename), "/proc/acpi/battery/%s/state", ent->d_name); if ((len < 0) || ((unsigned int)len >= sizeof (filename))) diff --git a/src/collectd.c b/src/collectd.c index d2ca5687..2044b49c 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -86,8 +86,7 @@ static int init_hostname (void) str = global_option_get ("Hostname"); if (str != NULL) { - strncpy (hostname_g, str, sizeof (hostname_g)); - hostname_g[sizeof (hostname_g) - 1] = '\0'; + sstrncpy (hostname_g, str, sizeof (hostname_g)); return (0); } @@ -123,8 +122,7 @@ static int init_hostname (void) if (ai_ptr->ai_canonname == NULL) continue; - strncpy (hostname_g, ai_ptr->ai_canonname, sizeof (hostname_g)); - hostname_g[sizeof (hostname_g) - 1] = '\0'; + sstrncpy (hostname_g, ai_ptr->ai_canonname, sizeof (hostname_g)); break; } diff --git a/src/common.c b/src/common.c index 5c3db5dd..3f6eecc3 100644 --- a/src/common.c +++ b/src/common.c @@ -61,6 +61,19 @@ char *sstrncpy (char *dest, const char *src, size_t n) return (dest); } /* char *sstrncpy */ +int ssnprintf (char *dest, size_t n, const char *format, ...) +{ + int ret = 0; + va_list ap; + + va_start (ap, format); + ret = vsnprintf (dest, n, format, ap); + dest[n - 1] = '\0'; + va_end (ap); + + return (ret); +} /* int ssnprintf */ + char *sstrdup (const char *s) { char *r; @@ -91,7 +104,7 @@ char *sstrerror (int errnum, char *buf, size_t buflen) pthread_mutex_lock (&strerror_r_lock); temp = strerror (errnum); - strncpy (buf, temp, buflen); + sstrncpy (buf, temp, buflen); pthread_mutex_unlock (&strerror_r_lock); } @@ -104,9 +117,9 @@ char *sstrerror (int errnum, char *buf, size_t buflen) if (buf[0] == '\0') { if ((temp != NULL) && (temp != buf) && (temp[0] != '\0')) - strncpy (buf, temp, buflen); + sstrncpy (buf, temp, buflen); else - strncpy (buf, "strerror_r did not return " + sstrncpy (buf, "strerror_r did not return " "an error message", buflen); } } @@ -115,13 +128,12 @@ char *sstrerror (int errnum, char *buf, size_t buflen) #else if (strerror_r (errnum, buf, buflen) != 0) { - snprintf (buf, buflen, "Error #%i; " + ssnprintf (buf, buflen, "Error #%i; " "Additionally, strerror_r failed.", errnum); } #endif /* STRERROR_R_CHAR_P */ - buf[buflen - 1] = '\0'; return (buf); } /* char *sstrerror */ @@ -376,7 +388,7 @@ int check_create_dir (const char *file_orig) if ((len = strlen (file_orig)) < 1) return (-1); - else if (len >= 512) + else if (len >= sizeof (file_copy)) return (-1); /* @@ -391,8 +403,7 @@ int check_create_dir (const char *file_orig) /* * Create a copy for `strtok_r' to destroy */ - strncpy (file_copy, file_orig, 512); - file_copy[511] = '\0'; + sstrncpy (file_copy, file_orig, sizeof (file_copy)); /* * Break into components. This will eat up several slashes in a row and @@ -477,8 +488,7 @@ int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name) if (kc == NULL) return (-1); - snprintf (ident, 128, "%s,%i,%s", module, instance, name); - ident[127] = '\0'; + ssnprintf (ident, sizeof (ident), "%s,%i,%s", module, instance, name); if (*ksp_ptr == NULL) { @@ -663,21 +673,21 @@ int format_name (char *ret, int ret_len, if ((plugin_instance == NULL) || (strlen (plugin_instance) == 0)) { if ((type_instance == NULL) || (strlen (type_instance) == 0)) - status = snprintf (ret, ret_len, "%s/%s/%s", + status = ssnprintf (ret, ret_len, "%s/%s/%s", hostname, plugin, type); else - status = snprintf (ret, ret_len, "%s/%s/%s-%s", + status = ssnprintf (ret, ret_len, "%s/%s/%s-%s", hostname, plugin, type, type_instance); } else { if ((type_instance == NULL) || (strlen (type_instance) == 0)) - status = snprintf (ret, ret_len, "%s/%s-%s/%s", + status = ssnprintf (ret, ret_len, "%s/%s-%s/%s", hostname, plugin, plugin_instance, type); else - status = snprintf (ret, ret_len, "%s/%s-%s/%s-%s", + status = ssnprintf (ret, ret_len, "%s/%s-%s/%s-%s", hostname, plugin, plugin_instance, type, type_instance); } @@ -838,26 +848,19 @@ int notification_init (notification_t *n, int severity, const char *message, n->severity = severity; if (message != NULL) - strncpy (n->message, message, sizeof (n->message)); + sstrncpy (n->message, message, sizeof (n->message)); if (host != NULL) - strncpy (n->host, host, sizeof (n->host)); + sstrncpy (n->host, host, sizeof (n->host)); if (plugin != NULL) - strncpy (n->plugin, plugin, sizeof (n->plugin)); + sstrncpy (n->plugin, plugin, sizeof (n->plugin)); if (plugin_instance != NULL) - strncpy (n->plugin_instance, plugin_instance, + sstrncpy (n->plugin_instance, plugin_instance, sizeof (n->plugin_instance)); if (type != NULL) - strncpy (n->type, type, sizeof (n->type)); + sstrncpy (n->type, type, sizeof (n->type)); if (type_instance != NULL) - strncpy (n->type_instance, type_instance, + sstrncpy (n->type_instance, type_instance, sizeof (n->type_instance)); - n->message[sizeof (n->message) - 1] = '\0'; - n->host[sizeof (n->host) - 1] = '\0'; - n->plugin[sizeof (n->plugin) - 1] = '\0'; - n->plugin_instance[sizeof (n->plugin_instance) - 1] = '\0'; - n->type[sizeof (n->type) - 1] = '\0'; - n->type_instance[sizeof (n->type_instance) - 1] = '\0'; - return (0); } /* int notification_init */ diff --git a/src/common.h b/src/common.h index e99aea69..d142679f 100644 --- a/src/common.h +++ b/src/common.h @@ -39,6 +39,7 @@ #define STATIC_ARRAY_SIZE(a) (sizeof (a) / sizeof (*(a))) char *sstrncpy (char *dest, const char *src, size_t n); +int ssnprintf (char *dest, size_t n, const char *format, ...); char *sstrdup(const char *s); void *smalloc(size_t size); char *sstrerror (int errnum, char *buf, size_t buflen); diff --git a/src/configfile.c b/src/configfile.c index 4a9789ae..2afef4f0 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -182,8 +182,7 @@ static int dispatch_global_option (const oconfig_item_t *ci) else if (ci->values[0].type == OCONFIG_TYPE_NUMBER) { char tmp[128]; - snprintf (tmp, sizeof (tmp), "%lf", ci->values[0].value.number); - tmp[127] = '\0'; + ssnprintf (tmp, sizeof (tmp), "%lf", ci->values[0].value.number); return (global_option_set (ci->key, tmp)); } else if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN) @@ -258,13 +257,13 @@ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci) int status = -1; if (ci->values[i].type == OCONFIG_TYPE_STRING) - status = snprintf (buffer_ptr, buffer_free, " %s", + status = ssnprintf (buffer_ptr, buffer_free, " %s", ci->values[i].value.string); else if (ci->values[i].type == OCONFIG_TYPE_NUMBER) - status = snprintf (buffer_ptr, buffer_free, " %lf", + status = ssnprintf (buffer_ptr, buffer_free, " %lf", ci->values[i].value.number); else if (ci->values[i].type == OCONFIG_TYPE_BOOLEAN) - status = snprintf (buffer_ptr, buffer_free, " %s", + status = ssnprintf (buffer_ptr, buffer_free, " %s", ci->values[i].value.boolean ? "true" : "false"); @@ -548,7 +547,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, int depth) if ((de->d_name[0] == '.') || (de->d_name[0] == '\0')) continue; - status = snprintf (name, sizeof (name), "%s/%s", + status = ssnprintf (name, sizeof (name), "%s/%s", dir, de->d_name); if (status >= sizeof (name)) { diff --git a/src/cpu.c b/src/cpu.c index 49d5effc..4d24125c 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -169,11 +169,10 @@ static void submit (int cpu_num, const char *type_instance, counter_t value) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "cpu"); - snprintf (vl.plugin_instance, sizeof (vl.type_instance), + ssnprintf (vl.plugin_instance, sizeof (vl.type_instance), "%i", cpu_num); - vl.plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0'; strcpy (vl.type, "cpu"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } diff --git a/src/cpufreq.c b/src/cpufreq.c index 5cb1b4e3..f4424e65 100644 --- a/src/cpufreq.c +++ b/src/cpufreq.c @@ -37,7 +37,7 @@ static int cpufreq_init (void) while (1) { - status = snprintf (filename, sizeof (filename), + status = ssnprintf (filename, sizeof (filename), "/sys/devices/system/cpu/cpu%d/cpufreq/" "scaling_cur_freq", num_cpu); if ((status < 1) || ((unsigned int)status >= sizeof (filename))) @@ -71,7 +71,7 @@ static void cpufreq_submit (int cpu_num, double value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "cpufreq"); strcpy (vl.type, "cpufreq"); - snprintf (vl.type_instance, sizeof (vl.type_instance), + ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%i", cpu_num); plugin_dispatch_values (&vl); @@ -88,7 +88,7 @@ static int cpufreq_read (void) for (i = 0; i < num_cpu; i++) { - status = snprintf (filename, sizeof (filename), + status = ssnprintf (filename, sizeof (filename), "/sys/devices/system/cpu/cpu%d/cpufreq/" "scaling_cur_freq", i); if ((status < 1) || ((unsigned int)status >= sizeof (filename))) diff --git a/src/csv.c b/src/csv.c index b5de302e..a94b7001 100644 --- a/src/csv.c +++ b/src/csv.c @@ -49,7 +49,7 @@ static int value_list_to_string (char *buffer, int buffer_len, memset (buffer, '\0', buffer_len); - status = snprintf (buffer, buffer_len, "%u", (unsigned int) vl->time); + status = ssnprintf (buffer, buffer_len, "%u", (unsigned int) vl->time); if ((status < 1) || (status >= buffer_len)) return (-1); offset = status; @@ -64,7 +64,7 @@ static int value_list_to_string (char *buffer, int buffer_len, { if (store_rates == 0) { - status = snprintf (buffer + offset, + status = ssnprintf (buffer + offset, buffer_len - offset, ",%llu", vl->values[i].counter); @@ -79,14 +79,14 @@ static int value_list_to_string (char *buffer, int buffer_len, "uc_get_rate failed."); return (-1); } - status = snprintf (buffer + offset, + status = ssnprintf (buffer + offset, buffer_len - offset, ",%lf", rates[i]); } } else /* if (ds->ds[i].type == DS_TYPE_GAUGE) */ { - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, ",%lf", vl->values[i].gauge); } @@ -113,34 +113,34 @@ static int value_list_to_filename (char *buffer, int buffer_len, if (datadir != NULL) { - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", datadir); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; } - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", vl->host); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; if (strlen (vl->plugin_instance) > 0) - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s-%s/", vl->plugin, vl->plugin_instance); else - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", vl->plugin); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; if (strlen (vl->type_instance) > 0) - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s-%s", vl->type, vl->type_instance); else - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s", vl->type); if ((status < 1) || (status >= buffer_len - offset)) return (-1); diff --git a/src/df.c b/src/df.c index f4227435..284472b1 100644 --- a/src/df.c +++ b/src/df.c @@ -129,7 +129,7 @@ static void df_submit (char *df_name, strcpy (vl.plugin, "df"); strcpy (vl.plugin_instance, ""); strcpy (vl.type, "df"); - strncpy (vl.type_instance, df_name, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, df_name, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void df_submit */ @@ -174,13 +174,13 @@ static int df_read (void) if (strcmp (mnt_ptr->dir, "/") == 0) { - strncpy (mnt_name, "root", sizeof (mnt_name)); + sstrncpy (mnt_name, "root", sizeof (mnt_name)); } else { int i, len; - strncpy (mnt_name, mnt_ptr->dir + 1, sizeof (mnt_name)); + sstrncpy (mnt_name, mnt_ptr->dir + 1, sizeof (mnt_name)); len = strlen (mnt_name); for (i = 0; i < len; i++) diff --git a/src/disk.c b/src/disk.c index 50beb460..23bec09c 100644 --- a/src/disk.c +++ b/src/disk.c @@ -208,9 +208,9 @@ static void disk_submit (const char *plugin_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "disk"); - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); plugin_dispatch_values (&vl); } /* void disk_submit */ @@ -369,7 +369,8 @@ static int disk_read (void) write_tme = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsTotalWriteTimeKey); - if (snprintf (disk_name, 64, "%i-%i", disk_major, disk_minor) >= 64) + if (ssnprintf (disk_name, sizeof (disk_name), + "%i-%i", disk_major, disk_minor) >= sizeof (disk_name)) { DEBUG ("snprintf (major, minor) failed."); CFRelease (child_dict); diff --git a/src/dns.c b/src/dns.c index b61d768d..c315eab9 100644 --- a/src/dns.c +++ b/src/dns.c @@ -301,8 +301,8 @@ static void submit_counter (const char *type, const char *type_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "dns"); - strncpy (vl.type, type, sizeof (vl.type)); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void submit_counter */ diff --git a/src/email.c b/src/email.c index 50599c02..b255ac79 100644 --- a/src/email.c +++ b/src/email.c @@ -511,8 +511,7 @@ static void *open_connection (void *arg) addr.sun_family = AF_UNIX; - strncpy (addr.sun_path, sock_file, (size_t)(UNIX_PATH_MAX - 1)); - addr.sun_path[UNIX_PATH_MAX - 1] = '\0'; + sstrncpy (addr.sun_path, sock_file, sizeof (addr.sun_path)); unlink (addr.sun_path); errno = 0; @@ -735,8 +734,8 @@ static void email_submit (const char *type, const char *type_instance, gauge_t v vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "email"); - strncpy (vl.type, type, sizeof (vl.type)); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void email_submit */ diff --git a/src/exec.c b/src/exec.c index 07c35c9b..ac0175cf 100644 --- a/src/exec.c +++ b/src/exec.c @@ -170,10 +170,9 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ { char *tmp = strrchr (ci->values[1].value.string, '/'); if (tmp == NULL) - strncpy (buffer, ci->values[1].value.string, sizeof (buffer)); + sstrncpy (buffer, ci->values[1].value.string, sizeof (buffer)); else - strncpy (buffer, tmp + 1, sizeof (buffer)); - buffer[sizeof (buffer) - 1] = '\0'; + sstrncpy (buffer, tmp + 1, sizeof (buffer)); } pl->argv[0] = strdup (buffer); if (pl->argv[0] == NULL) @@ -196,17 +195,16 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ { if (ci->values[i + 1].type == OCONFIG_TYPE_NUMBER) { - snprintf (buffer, sizeof (buffer), "%lf", + ssnprintf (buffer, sizeof (buffer), "%lf", ci->values[i + 1].value.number); } else { if (ci->values[i + 1].value.boolean) - strncpy (buffer, "true", sizeof (buffer)); + sstrncpy (buffer, "true", sizeof (buffer)); else - strncpy (buffer, "false", sizeof (buffer)); + sstrncpy (buffer, "false", sizeof (buffer)); } - buffer[sizeof (buffer) - 1] = '\0'; pl->argv[i] = strdup (buffer); } diff --git a/src/hddtemp.c b/src/hddtemp.c index b4a50ac7..a9c09418 100644 --- a/src/hddtemp.c +++ b/src/hddtemp.c @@ -223,11 +223,10 @@ static int hddtemp_config (const char *key, const char *value) { int port = (int) (atof (value)); if ((port > 0) && (port <= 65535)) - snprintf (hddtemp_port, sizeof (hddtemp_port), + ssnprintf (hddtemp_port, sizeof (hddtemp_port), "%i", port); else - strncpy (hddtemp_port, value, sizeof (hddtemp_port)); - hddtemp_port[sizeof (hddtemp_port) - 1] = '\0'; + sstrncpy (hddtemp_port, value, sizeof (hddtemp_port)); } else if (strcasecmp (key, "TranslateDevicename") == 0) { @@ -430,7 +429,7 @@ static char *hddtemp_get_major_minor (char *drive) if ((ret = (char *) malloc (128 * sizeof (char))) == NULL) return (NULL); - if (snprintf (ret, 128, "%i-%i", list->major, list->minor) >= 128) + if (ssnprintf (ret, 128, "%i-%i", list->major, list->minor) >= 128) { free (ret); return (NULL); @@ -452,7 +451,7 @@ static void hddtemp_submit (char *type_instance, double value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "hddtemp"); strcpy (vl.type, "temperature"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } diff --git a/src/interface.c b/src/interface.c index 6edecc4d..ef758bc8 100644 --- a/src/interface.c +++ b/src/interface.c @@ -195,8 +195,8 @@ static void if_submit (const char *dev, const char *type, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "interface"); - strncpy (vl.type, type, sizeof (vl.type)); - strncpy (vl.type_instance, dev, sizeof (vl.type_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, dev, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void if_submit */ diff --git a/src/iptables.c b/src/iptables.c index 5e9619af..576cd63e 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -112,8 +112,7 @@ static int iptables_config (const char *key, const char *value) free (value_copy); return (1); } - strncpy (temp.table, table, table_len); - temp.table[table_len] = '\0'; + sstrncpy (temp.table, table, table_len); chain_len = strlen (chain); if ((unsigned int)chain_len >= sizeof(temp.chain)) @@ -122,8 +121,7 @@ static int iptables_config (const char *key, const char *value) free (value_copy); return (1); } - strncpy (temp.chain, chain, chain_len); - temp.chain[chain_len] = '\0'; + sstrncpy (temp.chain, chain, chain_len); if (fields_num >= 3) { @@ -152,7 +150,7 @@ static int iptables_config (const char *key, const char *value) } if (fields_num >= 4) - strncpy (temp.name, fields[3], sizeof (temp.name) - 1); + sstrncpy (temp.name, fields[3], sizeof (temp.name)); free (value_copy); value_copy = NULL; @@ -222,25 +220,24 @@ static int submit_match (const struct ipt_entry_match *match, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "iptables"); - status = snprintf (vl.plugin_instance, sizeof (vl.plugin_instance), + status = ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%s-%s", chain->table, chain->chain); if ((status < 1) || ((unsigned int)status >= sizeof (vl.plugin_instance))) return (0); if (chain->name[0] != '\0') { - strncpy (vl.type_instance, chain->name, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, chain->name, sizeof (vl.type_instance)); } else { if (chain->rule_type == RTYPE_NUM) - snprintf (vl.type_instance, sizeof (vl.type_instance), + ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%i", chain->rule.num); else - strncpy (vl.type_instance, (char *) match->data, + sstrncpy (vl.type_instance, (char *) match->data, sizeof (vl.type_instance)); } - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; strcpy (vl.type, "ipt_bytes"); values[0].counter = (counter_t) entry->counters.bcnt; diff --git a/src/ipvs.c b/src/ipvs.c index c5054a83..a64e7b7a 100644 --- a/src/ipvs.c +++ b/src/ipvs.c @@ -191,7 +191,7 @@ static int get_pi (struct ip_vs_service_entry *se, char *pi, size_t size) /* inet_ntoa() returns a pointer to a statically allocated buffer * I hope non-glibc systems behave the same */ - len = snprintf (pi, size, "%s_%s%u", inet_ntoa (addr), + len = ssnprintf (pi, size, "%s_%s%u", inet_ntoa (addr), (se->protocol == IPPROTO_TCP) ? "TCP" : "UDP", ntohs (se->port)); @@ -215,7 +215,7 @@ static int get_ti (struct ip_vs_dest_entry *de, char *ti, size_t size) /* inet_ntoa() returns a pointer to a statically allocated buffer * I hope non-glibc systems behave the same */ - len = snprintf (ti, size, "%s_%u", inet_ntoa (addr), + len = ssnprintf (ti, size, "%s_%u", inet_ntoa (addr), ntohs (de->port)); if ((0 > len) || (size <= len)) { @@ -240,9 +240,9 @@ static void cipvs_submit_connections (char *pi, char *ti, counter_t value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "ipvs"); - strncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance)); + sstrncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance)); strcpy (vl.type, "connections"); - strncpy (vl.type_instance, (NULL != ti) ? ti : "total", + sstrncpy (vl.type_instance, (NULL != ti) ? ti : "total", sizeof (vl.type_instance)); plugin_dispatch_values (&vl); @@ -266,9 +266,9 @@ static void cipvs_submit_if (char *pi, char *t, char *ti, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "ipvs"); - strncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance)); - strncpy (vl.type, t, sizeof (vl.type)); - strncpy (vl.type_instance, (NULL != ti) ? ti : "total", + sstrncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, t, sizeof (vl.type)); + sstrncpy (vl.type_instance, (NULL != ti) ? ti : "total", sizeof (vl.type_instance)); plugin_dispatch_values (&vl); diff --git a/src/irq.c b/src/irq.c index a8866b74..792ac346 100644 --- a/src/irq.c +++ b/src/irq.c @@ -136,7 +136,7 @@ static void irq_submit (unsigned int irq, counter_t value) strcpy (vl.plugin, "irq"); strcpy (vl.type, "irq"); - status = snprintf (vl.type_instance, sizeof (vl.type_instance), + status = ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%u", irq); if ((status < 1) || ((unsigned int)status >= sizeof (vl.type_instance))) return; diff --git a/src/libvirt.c b/src/libvirt.c index bd09abfa..370e794a 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -634,7 +634,7 @@ ignore_device_match (ignorelist_t *il, const char *domname, const char *devpath) ERROR ("libvirt plugin: malloc failed."); return 0; } - snprintf (name, n, "%s:%s", domname, devpath); + ssnprintf (name, n, "%s:%s", domname, devpath); r = ignorelist_match (il, name); free (name); return r; @@ -652,8 +652,7 @@ init_value_list (value_list_t *vl, time_t t, virDomainPtr dom) vl->time = t; vl->interval = interval_g; - strncpy (vl->plugin, "libvirt", sizeof (vl->plugin)); - vl->plugin[sizeof (vl->plugin) - 1] = '\0'; + sstrncpy (vl->plugin, "libvirt", sizeof (vl->plugin)); vl->host[0] = '\0'; host_ptr = vl->host; @@ -706,7 +705,7 @@ cpu_submit (unsigned long long cpu_time, vl.values = values; vl.values_len = 1; - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); plugin_dispatch_values (&vl); } @@ -725,9 +724,8 @@ vcpu_submit (counter_t cpu_time, vl.values = values; vl.values_len = 1; - strncpy (vl.type, type, sizeof (vl.type)); - snprintf (vl.type_instance, sizeof (vl.type_instance), "%d", vcpu_nr); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type, type, sizeof (vl.type)); + ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%d", vcpu_nr); plugin_dispatch_values (&vl); } @@ -747,9 +745,8 @@ submit_counter2 (const char *type, counter_t v0, counter_t v1, vl.values = values; vl.values_len = 2; - strncpy (vl.type, type, sizeof (vl.type)); - strncpy (vl.type_instance, devname, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, devname, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void submit_counter2 */ diff --git a/src/logfile.c b/src/logfile.c index 36ac58d7..382386b7 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -158,7 +158,7 @@ static int logfile_notification (const notification_t *n) int buf_len = sizeof (buf); int status; - status = snprintf (buf_ptr, buf_len, "Notification: severity = %s", + status = ssnprintf (buf_ptr, buf_len, "Notification: severity = %s", (n->severity == NOTIF_FAILURE) ? "FAILURE" : ((n->severity == NOTIF_WARNING) ? "WARNING" : ((n->severity == NOTIF_OKAY) ? "OKAY" : "UNKNOWN"))); @@ -170,7 +170,7 @@ static int logfile_notification (const notification_t *n) #define APPEND(bufptr, buflen, key, value) \ if ((buflen > 0) && (strlen (value) > 0)) { \ - int status = snprintf (bufptr, buflen, ", %s = %s", key, value); \ + int status = ssnprintf (bufptr, buflen, ", %s = %s", key, value); \ if (status > 0) { \ bufptr += status; \ buflen -= status; \ diff --git a/src/mbmon.c b/src/mbmon.c index e223b95c..923118f6 100644 --- a/src/mbmon.c +++ b/src/mbmon.c @@ -230,8 +230,8 @@ static void mbmon_submit (const char *type, const char *type_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "mbmon"); - strncpy (vl.type, type, sizeof (vl.type)); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void mbmon_submit */ diff --git a/src/memcached.c b/src/memcached.c index c2c8d27a..ca93102f 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -200,11 +200,10 @@ static int memcached_config (const char *key, const char *value) /* {{{ */ } else if (strcasecmp (key, "Port") == 0) { int port = (int) (atof (value)); if ((port > 0) && (port <= 65535)) { - snprintf (memcached_port, sizeof (memcached_port), "%i", port); + ssnprintf (memcached_port, sizeof (memcached_port), "%i", port); } else { - strncpy (memcached_port, value, sizeof (memcached_port)); + sstrncpy (memcached_port, value, sizeof (memcached_port)); } - memcached_port[sizeof (memcached_port) - 1] = '\0'; } else { return -1; } @@ -226,12 +225,9 @@ static void submit_counter (const char *type, const char *type_inst, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "memcached"); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void memcached_submit_cmd */ @@ -251,12 +247,9 @@ static void submit_counter2 (const char *type, const char *type_inst, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "memcached"); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void memcached_submit_cmd */ @@ -275,12 +268,9 @@ static void submit_gauge (const char *type, const char *type_inst, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "memcached"); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } @@ -300,12 +290,9 @@ static void submit_gauge2 (const char *type, const char *type_inst, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "memcached"); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) - { - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } diff --git a/src/memory.c b/src/memory.c index 5cb574dc..c9cb8340 100644 --- a/src/memory.c +++ b/src/memory.c @@ -104,8 +104,7 @@ static void memory_submit (const char *type_instance, gauge_t value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "memory"); strcpy (vl.type, "memory"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } diff --git a/src/mysql.c b/src/mysql.c index 5994183b..444acaa2 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -128,8 +128,8 @@ static void counter_submit (const char *type, const char *type_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "mysql"); - strncpy (vl.type, type, sizeof (vl.type)); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void counter_submit */ diff --git a/src/netlink.c b/src/netlink.c index 55371c33..f597b01d 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -173,11 +173,11 @@ static void submit_one (const char *dev, const char *type, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "netlink"); - strncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void submit_one */ @@ -197,11 +197,11 @@ static void submit_two (const char *dev, const char *type, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "netlink"); - strncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void submit_two */ @@ -397,11 +397,10 @@ static int qos_filter (const struct sockaddr_nl *sa, if (strcmp (tc_type, "filter") == 0) numberic_id = msg->tcm_parent; - snprintf (tc_inst, sizeof (tc_inst), "%s-%x:%x", + ssnprintf (tc_inst, sizeof (tc_inst), "%s-%x:%x", (const char *) RTA_DATA (attrs[TCA_KIND]), numberic_id >> 16, numberic_id & 0x0000FFFF); - tc_inst[sizeof (tc_inst) - 1] = '\0'; } DEBUG ("netlink plugin: qos_filter: got %s for %s (%i).", @@ -423,9 +422,8 @@ static int qos_filter (const struct sockaddr_nl *sa, struct gnet_stats_basic bs; char type_instance[DATA_MAX_NAME_LEN]; - snprintf (type_instance, sizeof (type_instance), "%s-%s", + ssnprintf (type_instance, sizeof (type_instance), "%s-%s", tc_type, tc_inst); - type_instance[sizeof (type_instance) - 1] = '\0'; memset (&bs, '\0', sizeof (bs)); memcpy (&bs, RTA_DATA (attrs_stats[TCA_STATS_BASIC]), @@ -445,9 +443,8 @@ static int qos_filter (const struct sockaddr_nl *sa, struct tc_stats ts; char type_instance[DATA_MAX_NAME_LEN]; - snprintf (type_instance, sizeof (type_instance), "%s-%s", + ssnprintf (type_instance, sizeof (type_instance), "%s-%s", tc_type, tc_inst); - type_instance[sizeof (type_instance) - 1] = '\0'; memset(&ts, '\0', sizeof (ts)); memcpy(&ts, RTA_DATA (attrs[TCA_STATS]), diff --git a/src/nfs.c b/src/nfs.c index 367e7142..34f01f43 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -190,14 +190,14 @@ static void nfs_procedures_submit (const char *plugin_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "nfs"); - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); strcpy (vl.type, "nfs_procedure"); for (i = 0; i < len; i++) { values[0].counter = val[i]; - strncpy (vl.type_instance, names[i], + sstrncpy (vl.type_instance, names[i], sizeof (vl.type_instance)); DEBUG ("%s-%s/nfs_procedure-%s = %llu", vl.plugin, vl.plugin_instance, @@ -241,9 +241,8 @@ static void nfs_read_stats_file (FILE *fh, char *inst) continue; } - snprintf (plugin_instance, sizeof (plugin_instance), + ssnprintf (plugin_instance, sizeof (plugin_instance), "v2%s", inst); - plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0'; values = (unsigned long long *) malloc (nfs2_procedures_names_num * sizeof (unsigned long long)); if (values == NULL) @@ -278,9 +277,8 @@ static void nfs_read_stats_file (FILE *fh, char *inst) continue; } - snprintf (plugin_instance, sizeof (plugin_instance), + ssnprintf (plugin_instance, sizeof (plugin_instance), "v3%s", inst); - plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0'; values = (unsigned long long *) malloc (nfs3_procedures_names_num * sizeof (unsigned long long)); if (values == NULL) diff --git a/src/nginx.c b/src/nginx.c index a95362be..4de59f37 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -122,7 +122,8 @@ static int init (void) if (user != NULL) { - if (snprintf (credentials, 1024, "%s:%s", user, pass == NULL ? "" : pass) >= 1024) + if (ssnprintf (credentials, sizeof (credentials), + "%s:%s", user, pass == NULL ? "" : pass) >= sizeof (credentials)) { ERROR ("nginx plugin: Credentials would have been truncated."); return (-1); @@ -180,13 +181,10 @@ static void submit (char *type, char *inst, long long value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "nginx"); strcpy (vl.plugin_instance, ""); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (inst != NULL) - { - strncpy (vl.type_instance, inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, inst, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void submit */ diff --git a/src/ntpd.c b/src/ntpd.c index 81b74ef8..600c0a34 100644 --- a/src/ntpd.c +++ b/src/ntpd.c @@ -269,11 +269,10 @@ static int ntpd_config (const char *key, const char *value) { int port = (int) (atof (value)); if ((port > 0) && (port <= 65535)) - snprintf (ntpd_port, sizeof (ntpd_port), + ssnprintf (ntpd_port, sizeof (ntpd_port), "%i", port); else - strncpy (ntpd_port, value, sizeof (ntpd_port)); - ntpd_port[sizeof (ntpd_port) - 1] = '\0'; + sstrncpy (ntpd_port, value, sizeof (ntpd_port)); } else if (strcasecmp (key, "ReverseLookups") == 0) { @@ -305,8 +304,8 @@ static void ntpd_submit (char *type, char *type_inst, double value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "ntpd"); strcpy (vl.plugin_instance, ""); - strncpy (vl.type, type, sizeof (vl.type)); - strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } @@ -875,7 +874,7 @@ static int ntpd_read (void) if (refclock_id < refclock_names_num) { - strncpy (peername, refclock_names[refclock_id], + sstrncpy (peername, refclock_names[refclock_id], sizeof (peername)); } else @@ -884,7 +883,7 @@ static int ntpd_read (void) addr_obj.s_addr = ptr->srcadr; addr_str = inet_ntoa (addr_obj); - strncpy (peername, addr_str, sizeof (peername)); + sstrncpy (peername, addr_str, sizeof (peername)); } } else /* Normal network host. */ diff --git a/src/nut.c b/src/nut.c index bcb0ae95..75504d40 100644 --- a/src/nut.c +++ b/src/nut.c @@ -124,19 +124,15 @@ static void nut_submit (nut_ups_t *ups, const char *type, vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); vl.time = time (NULL); - strncpy (vl.host, + sstrncpy (vl.host, (strcasecmp (ups->hostname, "localhost") == 0) ? hostname_g : ups->hostname, sizeof (vl.host)); strcpy (vl.plugin, "nut"); - strncpy (vl.plugin_instance, ups->upsname, sizeof (vl.plugin_instance)); - strncpy (vl.type, type, sizeof (vl.type)); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - - vl.host[sizeof (vl.host) - 1] = '\0'; - vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0'; - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.plugin_instance, ups->upsname, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void nut_submit */ diff --git a/src/perl.c b/src/perl.c index 0f7d1141..a08cced1 100644 --- a/src/perl.c +++ b/src/perl.c @@ -204,8 +204,7 @@ static int hv2data_source (pTHX_ HV *hash, data_source_t *ds) return -1; if (NULL != (tmp = hv_fetch (hash, "name", 4, 0))) { - strncpy (ds->name, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN); - ds->name[DATA_MAX_NAME_LEN - 1] = '\0'; + sstrncpy (ds->name, SvPV_nolen (*tmp), sizeof (ds->name)); } else { log_err ("hv2data_source: No DS name given."); @@ -422,12 +421,11 @@ static int notification2hv (pTHX_ notification_t *n, HV *hash) static char *get_module_name (char *buf, size_t buf_len, const char *module) { int status = 0; if (base_name[0] == '\0') - status = snprintf (buf, buf_len, "%s", module); + status = ssnprintf (buf, buf_len, "%s", module); else - status = snprintf (buf, buf_len, "%s::%s", base_name, module); + status = ssnprintf (buf, buf_len, "%s::%s", base_name, module); if ((status < 0) || ((unsigned int)status >= buf_len)) return (NULL); - buf[buf_len - 1] = '\0'; return (buf); } /* char *get_module_name */ @@ -473,8 +471,7 @@ static int pplugin_register_data_set (pTHX_ char *name, AV *dataset) ds[i].name, ds[i].type, ds[i].min, ds[i].max); } - strncpy (set->type, name, DATA_MAX_NAME_LEN); - set->type[DATA_MAX_NAME_LEN - 1] = '\0'; + sstrncpy (set->type, name, sizeof (set->type)); set->ds_num = len + 1; set->ds = ds; @@ -526,8 +523,7 @@ static int pplugin_dispatch_values (pTHX_ HV *values) return -1; } - strncpy (list.type, SvPV_nolen (*tmp), sizeof (list.type)); - list.type[DATA_MAX_NAME_LEN - 1] = '\0'; + sstrncpy (list.type, SvPV_nolen (*tmp), sizeof (list.type)); if ((NULL == (tmp = hv_fetch (values, "values", 6, 0))) || (! (SvROK (*tmp) && (SVt_PVAV == SvTYPE (SvRV (*tmp)))))) { @@ -562,27 +558,22 @@ static int pplugin_dispatch_values (pTHX_ HV *values) } if (NULL != (tmp = hv_fetch (values, "host", 4, 0))) { - strncpy (list.host, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN); - list.host[DATA_MAX_NAME_LEN - 1] = '\0'; + sstrncpy (list.host, SvPV_nolen (*tmp), sizeof (list.host)); } else { strcpy (list.host, hostname_g); } - if (NULL != (tmp = hv_fetch (values, "plugin", 6, 0))) { - strncpy (list.plugin, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN); - list.plugin[DATA_MAX_NAME_LEN - 1] = '\0'; - } + if (NULL != (tmp = hv_fetch (values, "plugin", 6, 0))) + sstrncpy (list.plugin, SvPV_nolen (*tmp), sizeof (list.plugin)); - if (NULL != (tmp = hv_fetch (values, "plugin_instance", 15, 0))) { - strncpy (list.plugin_instance, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN); - list.plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0'; - } + if (NULL != (tmp = hv_fetch (values, "plugin_instance", 15, 0))) + sstrncpy (list.plugin_instance, SvPV_nolen (*tmp), + sizeof (list.plugin_instance)); - if (NULL != (tmp = hv_fetch (values, "type_instance", 13, 0))) { - strncpy (list.type_instance, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN); - list.type_instance[DATA_MAX_NAME_LEN - 1] = '\0'; - } + if (NULL != (tmp = hv_fetch (values, "type_instance", 13, 0))) + sstrncpy (list.type_instance, SvPV_nolen (*tmp), + sizeof (list.type_instance)); ret = plugin_dispatch_values (&list); @@ -627,31 +618,25 @@ static int pplugin_dispatch_notification (pTHX_ HV *notif) n.time = time (NULL); if (NULL != (tmp = hv_fetch (notif, "message", 7, 0))) - strncpy (n.message, SvPV_nolen (*tmp), sizeof (n.message)); - n.message[sizeof (n.message) - 1] = '\0'; + sstrncpy (n.message, SvPV_nolen (*tmp), sizeof (n.message)); if (NULL != (tmp = hv_fetch (notif, "host", 4, 0))) - strncpy (n.host, SvPV_nolen (*tmp), sizeof (n.host)); + sstrncpy (n.host, SvPV_nolen (*tmp), sizeof (n.host)); else - strncpy (n.host, hostname_g, sizeof (n.host)); - n.host[sizeof (n.host) - 1] = '\0'; + sstrncpy (n.host, hostname_g, sizeof (n.host)); if (NULL != (tmp = hv_fetch (notif, "plugin", 6, 0))) - strncpy (n.plugin, SvPV_nolen (*tmp), sizeof (n.plugin)); - n.plugin[sizeof (n.plugin) - 1] = '\0'; + sstrncpy (n.plugin, SvPV_nolen (*tmp), sizeof (n.plugin)); if (NULL != (tmp = hv_fetch (notif, "plugin_instance", 15, 0))) - strncpy (n.plugin_instance, SvPV_nolen (*tmp), + sstrncpy (n.plugin_instance, SvPV_nolen (*tmp), sizeof (n.plugin_instance)); - n.plugin_instance[sizeof (n.plugin_instance) - 1] = '\0'; if (NULL != (tmp = hv_fetch (notif, "type", 4, 0))) - strncpy (n.type, SvPV_nolen (*tmp), sizeof (n.type)); - n.type[sizeof (n.type) - 1] = '\0'; + sstrncpy (n.type, SvPV_nolen (*tmp), sizeof (n.type)); if (NULL != (tmp = hv_fetch (notif, "type_instance", 13, 0))) - strncpy (n.type_instance, SvPV_nolen (*tmp), sizeof (n.type_instance)); - n.type_instance[sizeof (n.type_instance) - 1] = '\0'; + sstrncpy (n.type_instance, SvPV_nolen (*tmp), sizeof (n.type_instance)); return plugin_dispatch_notification (&n); } /* static int pplugin_dispatch_notification (HV *) */ @@ -1296,8 +1281,7 @@ static int g_pv_get (pTHX_ SV *var, MAGIC *mg) static int g_pv_set (pTHX_ SV *var, MAGIC *mg) { char *pv = mg->mg_ptr; - strncpy (pv, SvPV_nolen (var), DATA_MAX_NAME_LEN); - pv[DATA_MAX_NAME_LEN - 1] = '\0'; + sstrncpy (pv, SvPV_nolen (var), DATA_MAX_NAME_LEN); return 0; } /* static int g_pv_set (pTHX_ SV *, MAGIC *) */ @@ -1484,8 +1468,7 @@ static int perl_config_basename (pTHX_ oconfig_item_t *ci) value = ci->values[0].value.string; log_debug ("perl_config: Setting plugin basename to \"%s\"", value); - strncpy (base_name, value, sizeof (base_name)); - base_name[sizeof (base_name) - 1] = '\0'; + sstrncpy (base_name, value, sizeof (base_name)); return 0; } /* static int perl_config_basename (oconfig_item_it *) */ diff --git a/src/ping.c b/src/ping.c index f298785a..20388c37 100644 --- a/src/ping.c +++ b/src/ping.c @@ -190,7 +190,7 @@ static void ping_submit (char *host, double latency) strcpy (vl.plugin, "ping"); strcpy (vl.plugin_instance, ""); strcpy (vl.type, "ping"); - strncpy (vl.type_instance, host, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, host, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } diff --git a/src/plugin.c b/src/plugin.c index f5905808..a4f96f88 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -328,7 +328,8 @@ int plugin_load (const char *type) /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the * type when matching the filename */ - if (snprintf (typename, BUFSIZE, "%s.so", type) >= BUFSIZE) + if (ssnprintf (typename, sizeof (typename), + "%s.so", type) >= sizeof (typename)) { WARNING ("snprintf: truncated: `%s.so'", type); return (-1); @@ -348,7 +349,8 @@ int plugin_load (const char *type) if (strncasecmp (de->d_name, typename, typename_len)) continue; - if (snprintf (filename, BUFSIZE, "%s/%s", dir, de->d_name) >= BUFSIZE) + if (ssnprintf (filename, sizeof (filename), + "%s/%s", dir, de->d_name) >= sizeof (filename)) { WARNING ("snprintf: truncated: `%s/%s'", dir, de->d_name); continue; diff --git a/src/powerdns.c b/src/powerdns.c index c82d4077..6a28856f 100644 --- a/src/powerdns.c +++ b/src/powerdns.c @@ -294,10 +294,9 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ memset (&sa_unix, 0, sizeof (sa_unix)); sa_unix.sun_family = AF_UNIX; - strncpy (sa_unix.sun_path, + sstrncpy (sa_unix.sun_path, (local_sockpath != NULL) ? local_sockpath : PDNS_LOCAL_SOCKPATH, sizeof (sa_unix.sun_path)); - sa_unix.sun_path[sizeof (sa_unix.sun_path) - 1] = 0; status = unlink (sa_unix.sun_path); if ((status != 0) && (errno != ENOENT)) @@ -664,7 +663,8 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */ } item->sockaddr.sun_family = AF_UNIX; - sstrncpy (item->sockaddr.sun_path, socket_temp, UNIX_PATH_MAX); + sstrncpy (item->sockaddr.sun_path, socket_temp, + sizeof (item->sockaddr.sun_path)); e = llentry_create (item->instance, item); if (e == NULL) diff --git a/src/processes.c b/src/processes.c index 1b413725..8275022f 100644 --- a/src/processes.c +++ b/src/processes.c @@ -158,7 +158,7 @@ static void ps_list_register (const char *name) if ((new = (procstat_t *) malloc (sizeof (procstat_t))) == NULL) return; memset (new, 0, sizeof (procstat_t)); - strncpy (new->name, name, PROCSTAT_NAME_LEN); + sstrncpy (new->name, name, sizeof (new->name)); for (ptr = list_head_g; ptr != NULL; ptr = ptr->next) { @@ -413,7 +413,7 @@ static void ps_submit_state (const char *state, double value) strcpy (vl.plugin, "processes"); strcpy (vl.plugin_instance, ""); strcpy (vl.type, "ps_state"); - strncpy (vl.type_instance, state, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, state, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } @@ -428,7 +428,7 @@ static void ps_submit_proc_list (procstat_t *ps) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "processes"); - strncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance)); + sstrncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance)); strcpy (vl.type, "ps_rss"); vl.values[0].gauge = ps->vmem_rss; @@ -472,8 +472,7 @@ static int *ps_read_tasks (int pid) DIR *dh; struct dirent *ent; - snprintf (dirname, 64, "/proc/%i/task", pid); - dirname[63] = '\0'; + ssnprintf (dirname, sizeof (dirname), "/proc/%i/task", pid); if ((dh = opendir (dirname)) == NULL) { @@ -545,8 +544,7 @@ int ps_read_process (int pid, procstat_t *ps, char *state) memset (ps, 0, sizeof (procstat_t)); - snprintf (filename, 64, "/proc/%i/stat", pid); - filename[63] = '\0'; + ssnprintf (filename, sizeof (filename), "/proc/%i/stat", pid); if ((fh = fopen (filename, "r")) == NULL) return (-1); diff --git a/src/rrdtool.c b/src/rrdtool.c index fad1e4b4..29e8a7d3 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -211,7 +211,7 @@ static int rra_get (char ***ret, const value_list_t *vl) if (rra_num >= rra_max) break; - if (snprintf (buffer, sizeof (buffer), "RRA:%s:%3.1f:%u:%u", + if (ssnprintf (buffer, sizeof (buffer), "RRA:%s:%3.1f:%u:%u", rra_types[j], xff, cdp_len, cdp_num) >= sizeof (buffer)) { @@ -284,26 +284,16 @@ static int ds_get (char ***ret, const data_set_t *ds, const value_list_t *vl) } if (isnan (d->min)) - { strcpy (min, "U"); - } else - { - snprintf (min, sizeof (min), "%lf", d->min); - min[sizeof (min) - 1] = '\0'; - } + ssnprintf (min, sizeof (min), "%lf", d->min); if (isnan (d->max)) - { strcpy (max, "U"); - } else - { - snprintf (max, sizeof (max), "%lf", d->max); - max[sizeof (max) - 1] = '\0'; - } + ssnprintf (max, sizeof (max), "%lf", d->max); - status = snprintf (buffer, sizeof (buffer), + status = ssnprintf (buffer, sizeof (buffer), "DS:%s:%s:%i:%s:%s", d->name, type, (heartbeat > 0) ? heartbeat : (2 * vl->interval), @@ -395,10 +385,8 @@ static int srrd_create (char *filename, unsigned long pdp_step, time_t last_up, if (last_up == 0) last_up = time (NULL) - 10; - snprintf (pdp_step_str, sizeof (pdp_step_str), "%lu", pdp_step); - pdp_step_str[sizeof (pdp_step_str) - 1] = '\0'; - snprintf (last_up_str, sizeof (last_up_str), "%u", (unsigned int) last_up); - last_up_str[sizeof (last_up_str) - 1] = '\0'; + ssnprintf (pdp_step_str, sizeof (pdp_step_str), "%lu", pdp_step); + ssnprintf (last_up_str, sizeof (last_up_str), "%u", (unsigned int) last_up); new_argv[0] = "create"; new_argv[1] = filename; @@ -531,7 +519,7 @@ static int value_list_to_string (char *buffer, int buffer_len, memset (buffer, '\0', buffer_len); - status = snprintf (buffer, buffer_len, "%u", (unsigned int) vl->time); + status = ssnprintf (buffer, buffer_len, "%u", (unsigned int) vl->time); if ((status < 1) || (status >= buffer_len)) return (-1); offset = status; @@ -543,10 +531,10 @@ static int value_list_to_string (char *buffer, int buffer_len, return (-1); if (ds->ds[i].type == DS_TYPE_COUNTER) - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, ":%llu", vl->values[i].counter); else - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, ":%lf", vl->values[i].gauge); if ((status < 1) || (status >= (buffer_len - offset))) @@ -566,34 +554,34 @@ static int value_list_to_filename (char *buffer, int buffer_len, if (datadir != NULL) { - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", datadir); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; } - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", vl->host); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; if (strlen (vl->plugin_instance) > 0) - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s-%s/", vl->plugin, vl->plugin_instance); else - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s/", vl->plugin); if ((status < 1) || (status >= buffer_len - offset)) return (-1); offset += status; if (strlen (vl->type_instance) > 0) - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s-%s.rrd", vl->type, vl->type_instance); else - status = snprintf (buffer + offset, buffer_len - offset, + status = ssnprintf (buffer + offset, buffer_len - offset, "%s.rrd", vl->type); if ((status < 1) || (status >= buffer_len - offset)) return (-1); diff --git a/src/sensors.c b/src/sensors.c index e69389c6..a0a4b65a 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -182,21 +182,21 @@ static int sensors_snprintf_chip_name (char *buf, size_t buf_size, if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA) { - status = snprintf (buf, buf_size, + status = ssnprintf (buf, buf_size, "%s-isa-%04x", chip->prefix, chip->addr); } else if (chip->bus == SENSORS_CHIP_NAME_BUS_DUMMY) { - snprintf (buf, buf_size, "%s-%s-%04x", + ssnprintf (buf, buf_size, "%s-%s-%04x", chip->prefix, chip->busname, chip->addr); } else { - snprintf (buf, buf_size, "%s-i2c-%d-%02x", + ssnprintf (buf, buf_size, "%s-i2c-%d-%02x", chip->prefix, chip->bus, chip->addr); @@ -480,11 +480,10 @@ static void sensors_submit (const char *plugin_instance, value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - status = snprintf (match_key, sizeof (match_key), "%s/%s-%s", + status = ssnprintf (match_key, sizeof (match_key), "%s/%s-%s", plugin_instance, type, type_instance); if (status < 1) return; - match_key[sizeof (match_key) - 1] = '\0'; if (sensor_list != NULL) { @@ -499,17 +498,12 @@ static void sensors_submit (const char *plugin_instance, vl.values_len = 1; vl.time = time (NULL); - strncpy (vl.host, hostname_g, sizeof (vl.host)); - vl.host[sizeof (vl.host) - 1] = '\0'; - strncpy (vl.plugin, "sensors", sizeof (vl.plugin)); - vl.plugin[sizeof (vl.plugin) - 1] = '\0'; - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "sensors", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0'; - strncpy (vl.type, type, sizeof (vl.type)); - vl.type[sizeof (vl.type) - 1] = '\0'; - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void sensors_submit */ @@ -538,11 +532,9 @@ static int sensors_read (void) sizeof (plugin_instance), fl->chip); if (status < 0) continue; - plugin_instance[sizeof (plugin_instance) - 1] = '\0'; - strncpy (type_instance, fl->data->name, + sstrncpy (type_instance, fl->data->name, sizeof (type_instance)); - type_instance[sizeof (type_instance) - 1] = '\0'; sensors_submit (plugin_instance, sensor_type_name_map[fl->type], @@ -569,11 +561,9 @@ static int sensors_read (void) sizeof (plugin_instance), fl->chip); if (status < 0) continue; - plugin_instance[sizeof (plugin_instance) - 1] = '\0'; - strncpy (type_instance, fl->feature->name, + sstrncpy (type_instance, fl->feature->name, sizeof (type_instance)); - type_instance[sizeof (type_instance) - 1] = '\0'; if (fl->feature->type == SENSORS_FEATURE_IN) type = "voltage"; diff --git a/src/serial.c b/src/serial.c index fb30fc4e..1c5d5a55 100644 --- a/src/serial.c +++ b/src/serial.c @@ -44,7 +44,7 @@ static void serial_submit (const char *type_instance, strcpy (vl.host, hostname_g); strcpy (vl.plugin, "serial"); strcpy (vl.type, "serial_octets"); - strncpy (vl.type_instance, type_instance, + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); diff --git a/src/snmp.c b/src/snmp.c index 77cc557c..6f11af04 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -198,7 +198,8 @@ static int csnmp_config_add_data_instance (data_definition_t *dd, oconfig_item_t else { /* Instance is a simple string */ - strncpy (dd->instance.string, ci->values[0].value.string, DATA_MAX_NAME_LEN - 1); + sstrncpy (dd->instance.string, ci->values[0].value.string, + sizeof (dd->instance.string)); } return (0); @@ -833,11 +834,10 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head, if (instance_len > vb->val_len) instance_len = vb->val_len; - strncpy (il->instance, (char *) ((vb->type == ASN_OCTET_STR) + sstrncpy (il->instance, (char *) ((vb->type == ASN_OCTET_STR) ? vb->val.string : vb->val.bitstring), instance_len); - il->instance[instance_len] = '\0'; for (ptr = il->instance; *ptr != '\0'; ptr++) { @@ -851,10 +851,9 @@ static int csnmp_instance_list_add (csnmp_list_instances_t **head, else { value_t val = csnmp_value_list_to_value (vb, DS_TYPE_COUNTER, 1.0, 0.0); - snprintf (il->instance, sizeof (il->instance), + ssnprintf (il->instance, sizeof (il->instance), "%llu", val.counter); } - il->instance[sizeof (il->instance) - 1] = '\0'; /* TODO: Debugging output */ @@ -907,8 +906,7 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat return (-1); } - strncpy (vl.host, host->name, sizeof (vl.host)); - vl.host[sizeof (vl.host) - 1] = '\0'; + sstrncpy (vl.host, host->name, sizeof (vl.host)); strcpy (vl.plugin, "snmp"); vl.interval = host->interval; @@ -972,25 +970,21 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat || (instance_list_ptr->subid == value_table_ptr[0]->subid)); #endif - strncpy (vl.type, data->type, sizeof (vl.type)); + sstrncpy (vl.type, data->type, sizeof (vl.type)); { char temp[DATA_MAX_NAME_LEN]; if (instance_list_ptr == NULL) - snprintf (temp, sizeof (temp), "%u", - (uint32_t) subid); + ssnprintf (temp, sizeof (temp), "%u", (uint32_t) subid); else - strncpy (temp, instance_list_ptr->instance, - sizeof (temp)); - temp[sizeof (temp) - 1] = '\0'; + sstrncpy (temp, instance_list_ptr->instance, sizeof (temp)); if (data->instance_prefix == NULL) - strncpy (vl.type_instance, temp, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, temp, sizeof (vl.type_instance)); else - snprintf (vl.type_instance, sizeof (vl.type_instance), "%s%s", + ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s%s", data->instance_prefix, temp); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; } for (i = 0; i < data->values_len; i++) @@ -1301,13 +1295,10 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) vl.values[i].gauge = NAN; } - strncpy (vl.host, host->name, sizeof (vl.host)); - vl.host[sizeof (vl.host) - 1] = '\0'; + sstrncpy (vl.host, host->name, sizeof (vl.host)); strcpy (vl.plugin, "snmp"); - strncpy (vl.type, data->type, sizeof (vl.type)); - vl.type[sizeof (vl.type) - 1] = '\0'; - strncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type, data->type, sizeof (vl.type)); + sstrncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance)); vl.interval = host->interval; diff --git a/src/swap.c b/src/swap.c index 632d372e..362a2a82 100644 --- a/src/swap.c +++ b/src/swap.c @@ -123,7 +123,7 @@ static void swap_submit (const char *type_instance, double value) strcpy (vl.host, hostname_g); strcpy (vl.plugin, "swap"); strcpy (vl.type, "swap"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void swap_submit */ diff --git a/src/tape.c b/src/tape.c index c374d598..67750efc 100644 --- a/src/tape.c +++ b/src/tape.c @@ -71,9 +71,9 @@ static void tape_submit (const char *plugin_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "tape"); - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); plugin_dispatch_values (&vl); } /* void tape_submit */ diff --git a/src/tcpconns.c b/src/tcpconns.c index 8c7beea5..4f46e78a 100644 --- a/src/tcpconns.c +++ b/src/tcpconns.c @@ -142,16 +142,14 @@ static void conn_submit_port_entry (port_entry_t *pe) if (((port_collect_listening != 0) && (pe->flags & PORT_IS_LISTENING)) || (pe->flags & PORT_COLLECT_LOCAL)) { - snprintf (vl.plugin_instance, sizeof (vl.plugin_instance), + ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%hu-local", pe->port); - vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0'; for (i = 1; i <= TCP_STATE_MAX; i++) { vl.values[0].gauge = pe->count_local[i]; - strncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } @@ -159,16 +157,14 @@ static void conn_submit_port_entry (port_entry_t *pe) if (pe->flags & PORT_COLLECT_REMOTE) { - snprintf (vl.plugin_instance, sizeof (vl.plugin_instance), + ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "%hu-remote", pe->port); - vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0'; for (i = 1; i <= TCP_STATE_MAX; i++) { vl.values[0].gauge = pe->count_remote[i]; - strncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; + sstrncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } diff --git a/src/teamspeak2.c b/src/teamspeak2.c index e3f12990..a945bbcd 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -376,8 +376,7 @@ static int tss2_select_vserver (FILE *read_fh, FILE *write_fh, vserver_list_t *v int status; /* Send request */ - snprintf (command, sizeof (command), "sel %i\r\n", vserver->port); - command[sizeof (command) - 1] = 0; + ssnprintf (command, sizeof (command), "sel %i\r\n", vserver->port); status = tss2_send_request (write_fh, command); if (status != 0) @@ -531,9 +530,8 @@ static int tss2_read_vserver (vserver_list_t *vserver) else { /* Request server information */ - snprintf (plugin_instance, sizeof (plugin_instance), "vserver%i", + ssnprintf (plugin_instance, sizeof (plugin_instance), "vserver%i", vserver->port); - plugin_instance[sizeof (plugin_instance) - 1] = 0; /* Select the server */ status = tss2_select_vserver (read_fh, write_fh, vserver); diff --git a/src/types_list.c b/src/types_list.c index 3be792d5..a9af9e6d 100644 --- a/src/types_list.c +++ b/src/types_list.c @@ -62,8 +62,7 @@ static int parse_ds (data_source_t *dsrc, char *buf, size_t buf_len) return (-1); } - strncpy (dsrc->name, fields[0], sizeof (dsrc->name)); - dsrc->name[sizeof (dsrc->name) - 1] = '\0'; + sstrncpy (dsrc->name, fields[0], sizeof (dsrc->name)); if (strcasecmp (fields[1], "GAUGE") == 0) dsrc->type = DS_TYPE_GAUGE; @@ -105,8 +104,7 @@ static void parse_line (char *buf) memset (ds, '\0', sizeof (data_set_t)); - strncpy (ds->type, fields[0], sizeof (ds->type)); - ds->type[sizeof (ds->type) - 1] = '\0'; + sstrncpy (ds->type, fields[0], sizeof (ds->type)); ds->ds_num = fields_num - 1; ds->ds = (data_source_t *) calloc (ds->ds_num, sizeof (data_source_t)); diff --git a/src/unixsock.c b/src/unixsock.c index 025c91d5..07598020 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -86,8 +86,8 @@ static int us_open_socket (void) memset (&sa, '\0', sizeof (sa)); sa.sun_family = AF_UNIX; - strncpy (sa.sun_path, (sock_file != NULL) ? sock_file : US_DEFAULT_PATH, - sizeof (sa.sun_path) - 1); + sstrncpy (sa.sun_path, (sock_file != NULL) ? sock_file : US_DEFAULT_PATH, + sizeof (sa.sun_path)); /* unlink (sa.sun_path); */ DEBUG ("unixsock plugin: socket path = %s", sa.sun_path); diff --git a/src/utils_cache.c b/src/utils_cache.c index 9f7e3b68..d7d31c53 100644 --- a/src/utils_cache.c +++ b/src/utils_cache.c @@ -156,13 +156,12 @@ static int uc_send_notification (const char *name) return (-1); } - snprintf (n.message, sizeof (n.message), + ssnprintf (n.message, sizeof (n.message), "%s has not been updated for %i seconds.", name, (int) (n.time - ce->last_update)); pthread_mutex_unlock (&cache_lock); - n.message[sizeof (n.message) - 1] = '\0'; plugin_dispatch_notification (&n); return (0); @@ -450,10 +449,9 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) n.severity = NOTIF_OKAY; n.time = vl->time; - snprintf (n.message, sizeof (n.message), + ssnprintf (n.message, sizeof (n.message), "Received a value for %s. It was missing for %u seconds.", name, (unsigned int) update_delay); - n.message[sizeof (n.message) - 1] = '\0'; plugin_dispatch_notification (&n); diff --git a/src/utils_dns.c b/src/utils_dns.c index 25ef1899..b72cd5ca 100644 --- a/src/utils_dns.c +++ b/src/utils_dns.c @@ -34,6 +34,7 @@ */ #include "collectd.h" +#include "common.h" #if HAVE_NETINET_IN_SYSTM_H # include @@ -813,8 +814,7 @@ const char *qtype_str(int t) case T_ANY: return ("ANY"); /* ... 255 */ #endif /* __BIND >= 19950621 */ default: - snprintf (buf, 32, "#%i", t); - buf[31] = '\0'; + ssnprintf (buf, sizeof (buf), "#%i", t); return (buf); }; /* switch (t) */ /* NOTREACHED */ @@ -841,7 +841,7 @@ const char *opcode_str (int o) return "Update"; break; default: - snprintf(buf, 30, "Opcode%d", o); + ssnprintf(buf, sizeof (buf), "Opcode%d", o); return buf; } /* NOTREACHED */ @@ -885,8 +885,7 @@ const char *rcode_str (int rcode) #endif /* RFC2136 rcodes */ #endif /* __BIND >= 19950621 */ default: - snprintf (buf, 32, "RCode%i", rcode); - buf[31] = '\0'; + ssnprintf (buf, sizeof (buf), "RCode%i", rcode); return (buf); } /* Never reached */ diff --git a/src/utils_ignorelist.c b/src/utils_ignorelist.c index 1d9467fe..518715b1 100644 --- a/src/utils_ignorelist.c +++ b/src/utils_ignorelist.c @@ -310,7 +310,7 @@ int ignorelist_add (ignorelist_t *il, const char *entry) /* We need to copy `entry' since it's const */ entry_copy = smalloc (entry_len); memset (entry_copy, '\0', entry_len); - strncpy (entry_copy, entry + 1, entry_len - 2); + sstrncpy (entry_copy, entry + 1, entry_len - 2); DEBUG("I'm about to add regex entry: %s", entry_copy); ret = ignorelist_append_regex(il, entry_copy); diff --git a/src/utils_mount.c b/src/utils_mount.c index 44ad7ea8..c53431f1 100644 --- a/src/utils_mount.c +++ b/src/utils_mount.c @@ -260,7 +260,7 @@ uuidcache_init(void) * (This is useful, if the cdrom on /dev/hdc must not * be accessed.) */ - snprintf(device, sizeof(device), "%s/%s", + ssnprintf(device, sizeof(device), "%s/%s", DEVLABELDIR, ptname); if(!get_label_uuid(device, &label, uuid)) { uuidcache_addentry(sstrdup(device), @@ -769,8 +769,6 @@ cu_mount_getoptionvalue(char *line, char *keyword) return r; } /* char *cu_mount_getoptionvalue(char *line, char *keyword) */ - - int cu_mount_type(const char *type) { @@ -782,5 +780,3 @@ cu_mount_type(const char *type) return CUMT_UNKNOWN; } /* int cu_mount_type(const char *type) */ - - diff --git a/src/utils_threshold.c b/src/utils_threshold.c index f65a1d80..91959b9d 100644 --- a/src/utils_threshold.c +++ b/src/utils_threshold.c @@ -184,9 +184,8 @@ static int ut_config_type_instance (threshold_t *th, oconfig_item_t *ci) return (-1); } - strncpy (th->type_instance, ci->values[0].value.string, + sstrncpy (th->type_instance, ci->values[0].value.string, sizeof (th->type_instance)); - th->type_instance[sizeof (th->type_instance) - 1] = '\0'; return (0); } /* int ut_config_type_instance */ @@ -284,8 +283,7 @@ static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci) } memcpy (&th, th_orig, sizeof (th)); - strncpy (th.type, ci->values[0].value.string, sizeof (th.type)); - th.type[sizeof (th.type) - 1] = '\0'; + sstrncpy (th.type, ci->values[0].value.string, sizeof (th.type)); th.warning_min = NAN; th.warning_max = NAN; @@ -340,9 +338,8 @@ static int ut_config_plugin_instance (threshold_t *th, oconfig_item_t *ci) return (-1); } - strncpy (th->plugin_instance, ci->values[0].value.string, + sstrncpy (th->plugin_instance, ci->values[0].value.string, sizeof (th->plugin_instance)); - th->plugin_instance[sizeof (th->plugin_instance) - 1] = '\0'; return (0); } /* int ut_config_plugin_instance */ @@ -369,8 +366,7 @@ static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci) } memcpy (&th, th_orig, sizeof (th)); - strncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin)); - th.plugin[sizeof (th.plugin) - 1] = '\0'; + sstrncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin)); for (i = 0; i < ci->children_num; i++) { @@ -417,8 +413,7 @@ static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci) } memcpy (&th, th_orig, sizeof (th)); - strncpy (th.host, ci->values[0].value.string, sizeof (th.host)); - th.host[sizeof (th.host) - 1] = '\0'; + sstrncpy (th.host, ci->values[0].value.string, sizeof (th.host)); for (i = 0; i < ci->children_num; i++) { @@ -596,26 +591,26 @@ static int ut_report_state (const data_set_t *ds, n.time = vl->time; - status = snprintf (buf, bufsize, "Host %s, plugin %s", + status = ssnprintf (buf, bufsize, "Host %s, plugin %s", vl->host, vl->plugin); buf += status; bufsize -= status; if (vl->plugin_instance[0] != '\0') { - status = snprintf (buf, bufsize, " (instance %s)", + status = ssnprintf (buf, bufsize, " (instance %s)", vl->plugin_instance); buf += status; bufsize -= status; } - status = snprintf (buf, bufsize, " type %s", vl->type); + status = ssnprintf (buf, bufsize, " type %s", vl->type); buf += status; bufsize -= status; if (vl->type_instance[0] != '\0') { - status = snprintf (buf, bufsize, " (instance %s)", + status = ssnprintf (buf, bufsize, " (instance %s)", vl->type_instance); buf += status; bufsize -= status; @@ -624,7 +619,7 @@ static int ut_report_state (const data_set_t *ds, /* Send an okay notification */ if (state == STATE_OKAY) { - status = snprintf (buf, bufsize, ": All data sources are within range again."); + status = ssnprintf (buf, bufsize, ": All data sources are within range again."); buf += status; bufsize -= status; } @@ -640,7 +635,7 @@ static int ut_report_state (const data_set_t *ds, { if (!isnan (min) && !isnan (max)) { - status = snprintf (buf, bufsize, ": Data source \"%s\" is currently " + status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " "%f. That is within the %s region of %f and %f.", ds->ds[ds_index].name, values[ds_index], (state == STATE_ERROR) ? "failure" : "warning", @@ -648,7 +643,7 @@ static int ut_report_state (const data_set_t *ds, } else { - status = snprintf (buf, bufsize, ": Data source \"%s\" is currently " + status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " "%f. That is %s the %s threshold of %f.", ds->ds[ds_index].name, values[ds_index], isnan (min) ? "below" : "above", @@ -658,7 +653,7 @@ static int ut_report_state (const data_set_t *ds, } else /* is not inverted */ { - status = snprintf (buf, bufsize, ": Data source \"%s\" is currently " + status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently " "%f. That is %s the %s threshold of %f.", ds->ds[ds_index].name, values[ds_index], (values[ds_index] < min) ? "below" : "above", @@ -864,24 +859,14 @@ int ut_check_interesting (const char *name) memset (&ds, '\0', sizeof (ds)); memset (&vl, '\0', sizeof (vl)); - strncpy (vl.host, host, sizeof (vl.host)); - vl.host[sizeof (vl.host) - 1] = '\0'; - strncpy (vl.plugin, plugin, sizeof (vl.plugin)); - vl.plugin[sizeof (vl.plugin) - 1] = '\0'; + sstrncpy (vl.host, host, sizeof (vl.host)); + sstrncpy (vl.plugin, plugin, sizeof (vl.plugin)); if (plugin_instance != NULL) - { - strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0'; - } - strncpy (ds.type, type, sizeof (ds.type)); - ds.type[sizeof (ds.type) - 1] = '\0'; - strncpy (vl.type, type, sizeof (vl.type)); - vl.type[sizeof (vl.type) - 1] = '\0'; + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (ds.type, type, sizeof (ds.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (type_instance != NULL) - { - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); sfree (name_copy); host = plugin = plugin_instance = type = type_instance = NULL; diff --git a/src/uuid.c b/src/uuid.c index d54301a2..e0de0d9b 100644 --- a/src/uuid.c +++ b/src/uuid.c @@ -257,8 +257,7 @@ uuid_init (void) char *uuid = uuid_get_local (); if (uuid) { - strncpy (hostname_g, uuid, DATA_MAX_NAME_LEN); - hostname_g[DATA_MAX_NAME_LEN-1] = '\0'; + sstrncpy (hostname_g, uuid, DATA_MAX_NAME_LEN); sfree (uuid); return 0; } diff --git a/src/vserver.c b/src/vserver.c index a2224030..4cc82516 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -59,9 +59,9 @@ static void traffic_submit (const char *plugin_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "vserver"); - strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); strcpy (vl.type, "if_octets"); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void traffic_submit */ @@ -81,7 +81,7 @@ static void load_submit (const char *plugin_instance, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "vserver"); - strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); strcpy (vl.type, "load"); plugin_dispatch_values (&vl); @@ -101,9 +101,9 @@ static void submit_gauge (const char *plugin_instance, const char *type, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "vserver"); - strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - strncpy (vl.type, type, sizeof (vl.type)); - strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* void submit_gauge */ @@ -150,8 +150,9 @@ static int vserver_read (void) continue; /* socket message accounting */ - len = snprintf (file, BUFSIZE, PROCDIR "/%s/cacct", dent->d_name); - if ((len < 0) || (len >= BUFSIZE)) + len = ssnprintf (file, sizeof (file), + PROCDIR "/%s/cacct", dent->d_name); + if ((len < 0) || (len >= sizeof (file))) continue; if (NULL == (fh = fopen (file, "r"))) @@ -197,8 +198,9 @@ static int vserver_read (void) } /* thread information and load */ - len = snprintf (file, BUFSIZE, PROCDIR "/%s/cvirt", dent->d_name); - if ((len < 0) || (len >= BUFSIZE)) + len = ssnprintf (file, sizeof (file), + PROCDIR "/%s/cvirt", dent->d_name); + if ((len < 0) || (len >= sizeof (file))) continue; if (NULL == (fh = fopen (file, "r"))) @@ -249,8 +251,9 @@ static int vserver_read (void) } /* processes and memory usage */ - len = snprintf (file, BUFSIZE, PROCDIR "/%s/limit", dent->d_name); - if ((len < 0) || (len >= BUFSIZE)) + len = ssnprintf (file, sizeof (file), + PROCDIR "/%s/limit", dent->d_name); + if ((len < 0) || (len >= sizeof (file))) continue; if (NULL == (fh = fopen (file, "r"))) diff --git a/src/wireless.c b/src/wireless.c index cc622e12..1282b48c 100644 --- a/src/wireless.c +++ b/src/wireless.c @@ -58,9 +58,9 @@ static void wireless_submit (const char *plugin_instance, const char *type, vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "wireless"); - strncpy (vl.plugin_instance, plugin_instance, + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); plugin_dispatch_values (&vl); } /* void wireless_submit */ diff --git a/src/xmms.c b/src/xmms.c index d6c1abc7..01c7e0cf 100644 --- a/src/xmms.c +++ b/src/xmms.c @@ -39,7 +39,7 @@ static void cxmms_submit (const char *type, gauge_t value) vl.time = time (NULL); strcpy (vl.host, hostname_g); strcpy (vl.plugin, "xmms"); - strncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type, type, sizeof (vl.type)); plugin_dispatch_values (&vl); } /* void cxmms_submit */