summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2354eda)
raw | patch | inline | side by side (parent: 2354eda)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 20 Apr 2008 21:20:45 +0000 (23:20 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Wed, 23 Apr 2008 13:40:26 +0000 (15:40 +0200) |
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 <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
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 <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
57 files changed:
diff --git a/src/apache.c b/src/apache.c
index 55d8cd479976481cf03aaf2abdd021491b857f09..7667f247604b330ace7f4426aef9d659a139c05c 100644 (file)
--- a/src/apache.c
+++ b/src/apache.c
{
int status;
- status = snprintf (credentials, sizeof (credentials), "%s:%s",
+ status = ssnprintf (credentials, sizeof (credentials), "%s:%s",
user, (pass == NULL) ? "" : pass);
if (status >= sizeof (credentials))
{
"truncated.");
return (-1);
}
- credentials[sizeof (credentials) - 1] = '\0';
curl_easy_setopt (curl, CURLOPT_USERPWD, credentials);
}
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 */
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 7f8afd461e4cacd6f2eeadca5e2a282039ba79bd..fb481092c18108dbed8d3be09fb41e6655457e26 100644 (file)
--- a/src/apcups.c
+++ b/src/apcups.c
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));
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 5db6e9c5e1911bb66cded4642013d63c251f662e..ee0bf8c09da13b2fb84fd487c0f9d906bccba6d5 100644 (file)
--- a/src/apple_sensors.c
+++ b/src/apple_sensors.c
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);
}
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;
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 e8ac0c2023b3a1002b5dae49973822d83835e146..6b4f21fc6b887b37b6ddfc70a8cdd5bfdd7e9018 100644 (file)
--- a/src/ascent.c
+++ b/src/ascent.c
{
int status;
- status = snprintf (credentials, sizeof (credentials), "%s:%s",
+ status = ssnprintf (credentials, sizeof (credentials), "%s:%s",
user, (pass == NULL) ? "" : pass);
if (status >= sizeof (credentials))
{
"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 0522015237d586897327b916f56d9602b1352223..f8e67a41aa1735748980f934c651a001747cb1ab 100644 (file)
--- a/src/battery.c
+++ b/src/battery.c
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 */
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;
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 d2ca56870c9e146a193ba498018d6952601c5513..2044b49cf8689184a756305d7e02d60616f0694c 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
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);
}
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 5c3db5ddacb53677d83e4d519f8b0c7331852449..3f6eecc363bde456e6dec8a96e79c14610e86031 100644 (file)
--- a/src/common.c
+++ b/src/common.c
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;
pthread_mutex_lock (&strerror_r_lock);
temp = strerror (errnum);
- strncpy (buf, temp, buflen);
+ sstrncpy (buf, temp, buflen);
pthread_mutex_unlock (&strerror_r_lock);
}
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);
}
}
#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 */
if ((len = strlen (file_orig)) < 1)
return (-1);
- else if (len >= 512)
+ else if (len >= sizeof (file_copy))
return (-1);
/*
/*
* 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
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)
{
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);
}
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 e99aea697e45f854b30a50d0b089b8cf20ddf406..d142679f6b908b3f562b32e2dd503068c0a2f396 100644 (file)
--- a/src/common.h
+++ b/src/common.h
#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 4a9789ae0a39e79285db024a457f9a5dc6e29fff..2afef4f024e402a2cc94bd7f02744e599fac440a 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
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)
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");
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 49d5effce840d6c78ea6a7e7ef24078c188a8891..4d24125cf1e7ed4d7667fe944f22ab146df988f6 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
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 5cb1b4e3fdb47ba1a43b1e771df246f66ae34919..f4424e6556af254d556a9b902be012fc8ff5ad83 100644 (file)
--- a/src/cpufreq.c
+++ b/src/cpufreq.c
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)))
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);
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 b5de302eefd4c21ce8c6e26a4b2d306fcd7889f4..a94b7001025419602961980efa993506e9755b33 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
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;
{
if (store_rates == 0)
{
- status = snprintf (buffer + offset,
+ status = ssnprintf (buffer + offset,
buffer_len - offset,
",%llu",
vl->values[i].counter);
"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);
}
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 f4227435a0cc7e556a3d9294042c9de5838e78b1..284472b1c21ebd5ade66bfcc59456b04db3bfd6d 100644 (file)
--- a/src/df.c
+++ b/src/df.c
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 */
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 50beb46096c14cf07c645152e49c97fdfe11e936..23bec09c0e3da44d846c1b9c003e72645d386add 100644 (file)
--- a/src/disk.c
+++ b/src/disk.c
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 */
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 b61d768df73a0705236fd2f11f83274653588736..c315eab960578f75df75476465726b387e9adf47 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
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 50599c02e052544c4b0e65ebdee008864fe4e8b5..b255ac79ea1f2f9230a3cdd0330bf80753a736e7 100644 (file)
--- a/src/email.c
+++ b/src/email.c
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 07c35c9bcf36d0e307ebbc48a93fb1e7fafa57e1..ac0175cf340a3eb04c3ca8d7175cb6155f755b03 100644 (file)
--- a/src/exec.c
+++ b/src/exec.c
{
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)
{
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 b4a50ac77f9ac7790db010dddae2c341ab8fb765..a9c094186516b699c7771249c29a026bbf2d2891 100644 (file)
--- a/src/hddtemp.c
+++ b/src/hddtemp.c
{
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)
{
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);
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 6edecc4d62991d8c02a984c74cc40dd4e14ad6cc..ef758bc8b374bf507e60c630dc72702a1e26858f 100644 (file)
--- a/src/interface.c
+++ b/src/interface.c
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 5e9619afc44186e8e3d1ba18c549325af08a9954..576cd63eabc0836d123c686dfde21405d7a18dcb 100644 (file)
--- a/src/iptables.c
+++ b/src/iptables.c
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))
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)
{
}
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;
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 c5054a8380b7eecfc715d2fb6996a5442bce4e1c..a64e7b7a99d56a4896c444235a10cf14090fbdf3 100644 (file)
--- a/src/ipvs.c
+++ b/src/ipvs.c
/* 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));
/* 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)) {
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);
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 a8866b744a18c3ee3f77aed7bd61a1edc9035620..792ac346fa83c3e0ac9df24c1844c2e0325e0d79 100644 (file)
--- a/src/irq.c
+++ b/src/irq.c
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 bd09abfa0103498c55fd791a17458c415ddadd5f..370e794a709f84547bb78924a6b26ada2b0b798d 100644 (file)
--- 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;
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;
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);
}
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);
}
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 36ac58d711ee8a1764fd19ec72fefc9afffeafc5..382386b75552fa0915d9ade6ded18bc5b9954f3d 100644 (file)
--- a/src/logfile.c
+++ b/src/logfile.c
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")));
#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 e223b95c4be158b23249efb6b7e06967ac0b821b..923118f62ceb486f88dcbbc0c363639e6360f681 100644 (file)
--- a/src/mbmon.c
+++ b/src/mbmon.c
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 c2c8d27add31524e6ca6879a660ad531751f7124..ca93102f2a2865a9ab2b1bbb3919f7b1b064d272 100644 (file)
--- a/src/memcached.c
+++ b/src/memcached.c
} 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;
}
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 */
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 */
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);
}
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 5cb574dc9f18ef3c8dace1d9e90a6e0041c526ac..c9cb83402fbf4c42d4164b379944778afebbc33a 100644 (file)
--- a/src/memory.c
+++ b/src/memory.c
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 5994183ba9743dc2257d48adc534eb23df42ea19..444acaa26aef33ed1d858e78564f52adec599f05 100644 (file)
--- a/src/mysql.c
+++ b/src/mysql.c
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 55371c33e421945198945f16ebd8b07a907eec01..f597b01d3243b5ad890b5e096b51ebca2273841b 100644 (file)
--- a/src/netlink.c
+++ b/src/netlink.c
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 */
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 */
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).",
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]),
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 367e7142ab2f67c1857634671ee00f991a114d97..34f01f43ecd2d0622cae93397e5ecdaa55acb0e6 100644 (file)
--- a/src/nfs.c
+++ b/src/nfs.c
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,
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)
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 a95362be4f7fd58a29cf3d2db610b0f4f4e71e48..4de59f3752b8827f28bf8885ec2f3c9073dd6c5d 100644 (file)
--- a/src/nginx.c
+++ b/src/nginx.c
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);
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 81b74ef8d483555484fb0da1ca9ecddd161efd74..600c0a34ac7411bd24cf0464c57b8d0e7c572a8f 100644 (file)
--- a/src/ntpd.c
+++ b/src/ntpd.c
{
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)
{
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);
}
if (refclock_id < refclock_names_num)
{
- strncpy (peername, refclock_names[refclock_id],
+ sstrncpy (peername, refclock_names[refclock_id],
sizeof (peername));
}
else
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 bcb0ae95650404fa69d8ad4bbfe9223ca7c69650..75504d408ef7e2f8bc4bce09dc128eb18fa246b8 100644 (file)
--- a/src/nut.c
+++ b/src/nut.c
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 0f7d114167e1950371c89e8855d52664abd2cdf1..a08cced1d3776453c50524d521004f0546e5e5b4 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
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.");
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 */
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;
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)))))) {
}
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);
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 *) */
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 *) */
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 f298785adfd97393bcf262a69e5a6f28eb344630..20388c370d4801f52a33e1b0c823a6bdea04ac11 100644 (file)
--- a/src/ping.c
+++ b/src/ping.c
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 f590580854bce472480ac48ff96c28ca9cbfa32a..a4f96f8834bb58cfaef158013df5db57be780b08 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
/* `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);
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 c82d4077e319acd34fce80833c207aae78d4db94..6a28856f69f0f17ede5d5de5589bfa6592329304 100644 (file)
--- a/src/powerdns.c
+++ b/src/powerdns.c
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))
}
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 1b413725d1cfbb0a662eb23ed422d358c7fc7efd..8275022f1120df9bb2c55374eb97d6d96bc4aebc 100644 (file)
--- a/src/processes.c
+++ b/src/processes.c
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)
{
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);
}
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;
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)
{
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 fad1e4b4455d5c6403df9ecc3a09522edade8981..29e8a7d30ba144f0f5ccaabd491b21cd422d7999 100644 (file)
--- a/src/rrdtool.c
+++ b/src/rrdtool.c
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))
{
}
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;
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;
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)))
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 e69389c621e0cc7d0bc2b29011a6e2501aa8f6ad..a0a4b65a2c5656de06910aac8c3f2d2dbb4fe8d7 100644 (file)
--- a/src/sensors.c
+++ b/src/sensors.c
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);
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)
{
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 */
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],
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 fb30fc4e7e01e2ea9b4408759cd58fa3b2ec9fcf..1c5d5a5594389a140d3de387e5d4e83237f5b5d2 100644 (file)
--- a/src/serial.c
+++ b/src/serial.c
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 77cc557ca87158762b3cf0dd7279dc69665f9577..6f11af045a7f7627b1e7feadf40e100ebb9f76aa 100644 (file)
--- 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);
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++)
{
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 632d372e1bc6e5e48acf5181691f7ddef6cb07e8..362a2a82963f573bc764bffa6c13952bdbbb9fd3 100644 (file)
--- a/src/swap.c
+++ b/src/swap.c
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 c374d59820e6dd1d7bc93083d831081594f2dec8..67750efc43868eb9134447447dbac7a4a44109e5 100644 (file)
--- a/src/tape.c
+++ b/src/tape.c
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 8c7beea5808fef6e6c29bc752b8e74a2bd45e40d..4f46e78abfd7a8cfab390b497957b010a021c4f6 100644 (file)
--- a/src/tcpconns.c
+++ b/src/tcpconns.c
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);
}
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 e3f12990450be955df0720d06bf24487d78deecb..a945bbcd377aca727bfab4fb4ec5ad30911a0e68 100644 (file)
--- 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)
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 3be792d5ca11bbd741f9b599a517c9cfea7da9ac..a9af9e6d29f783eeed53f8fb1836414511d77ac4 100644 (file)
--- a/src/types_list.c
+++ b/src/types_list.c
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;
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 025c91d5a6be76f6a2a94812af2f018782b17d43..0759802030a2d09b5d5ac13bbebf814557548bbd 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
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 9f7e3b686e52083f37871afc4f69391d1dd191bc..d7d31c53ec64642b97ff329a10a17f2be26a6188 100644 (file)
--- a/src/utils_cache.c
+++ b/src/utils_cache.c
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);
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 25ef18998bb9f62ad928130e49b531f71501f15f..b72cd5ca09c25283d5d54289b4e720dbc35f98fb 100644 (file)
--- a/src/utils_dns.c
+++ b/src/utils_dns.c
*/
#include "collectd.h"
+#include "common.h"
#if HAVE_NETINET_IN_SYSTM_H
# include <netinet/in_systm.h>
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 */
return "Update";
break;
default:
- snprintf(buf, 30, "Opcode%d", o);
+ ssnprintf(buf, sizeof (buf), "Opcode%d", o);
return buf;
}
/* NOTREACHED */
#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 1d9467fe210d89e6ce0f9c6537e3be9e389d6e8e..518715b1f48ada50c018e38f600dd6c14bcbd66f 100644 (file)
--- a/src/utils_ignorelist.c
+++ b/src/utils_ignorelist.c
/* 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 44ad7ea8642f98a222140ce9ced1babd7afdb39d..c53431f1a6458e8902b25ff2537f545e536b6269 100644 (file)
--- a/src/utils_mount.c
+++ b/src/utils_mount.c
* (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),
return r;
} /* char *cu_mount_getoptionvalue(char *line, char *keyword) */
-
-
int
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 f65a1d80eb53c565c7d690c3faa65d7cad83b02f..91959b9d4387f2389bbac1e8c8e01e95ee5701ae 100644 (file)
--- a/src/utils_threshold.c
+++ b/src/utils_threshold.c
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 */
}
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;
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 */
}
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++)
{
}
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++)
{
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;
/* 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;
}
{
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",
}
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",
}
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",
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 d54301a223bee899c430f4f1d19de617e8b78a4a..e0de0d9b314ed53575b7e5f00b08921a03834642 100644 (file)
--- a/src/uuid.c
+++ b/src/uuid.c
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 a22240303c8c17540372cbcdd3edbd1a859ed76c..4cc8251674afda0665ec270906cb9343e8469637 100644 (file)
--- a/src/vserver.c
+++ b/src/vserver.c
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 */
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);
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 */
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")))
}
/* 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")))
}
/* 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 cc622e12789dcf7945ce34c1c8dad3cfc218294d..1282b48c94b9db6bc55c59236fd76c3a60ba33f6 100644 (file)
--- a/src/wireless.c
+++ b/src/wireless.c
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 d6c1abc7668f041ba2360e8b9f42f927f91dbf72..01c7e0cfea9214cf536083614a2a9ac1b33129e8 100644 (file)
--- a/src/xmms.c
+++ b/src/xmms.c
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 */