From abaa1c8a24e8eff5632dd6052b1da5f6535caf19 Mon Sep 17 00:00:00 2001 From: Zebity Spring Date: Mon, 13 May 2019 23:19:22 +1000 Subject: [PATCH] Add snprintf wrapper for GCC 8.2/3 --- src/aggregation.c | 6 +++--- src/amqp.c | 12 +++++------ src/amqp1.c | 4 ++-- src/aquaero.c | 6 +++--- src/ascent.c | 2 +- src/ceph.c | 4 ++-- src/collectdctl.c | 21 ++++++++++++++++-- src/daemon/configfile.c | 12 +++++------ src/disk.c | 4 ++-- src/dpdkevents.c | 24 ++++++++++----------- src/dpdkstat.c | 4 ++-- src/gmond.c | 2 +- src/intel_rdt.c | 12 +++++------ src/interface.c | 2 +- src/ipmi.c | 26 +++++++++++------------ src/iptables.c | 8 +++---- src/lpar.c | 4 ++-- src/lua.c | 8 +++---- src/lvm.c | 2 +- src/mic.c | 10 ++++----- src/modbus.c | 4 ++-- src/mqtt.c | 4 ++-- src/mysql.c | 10 ++++----- src/netapp.c | 16 +++++++------- src/netlink.c | 6 +++--- src/nginx.c | 2 +- src/notify_desktop.c | 2 +- src/notify_email.c | 10 ++++----- src/onewire.c | 10 ++++----- src/openldap.c | 8 +++---- src/oracle.c | 2 +- src/ovs_events.c | 4 ++-- src/ovs_stats.c | 8 +++---- src/perl.c | 4 ++-- src/postgresql.c | 26 +++++++++++------------ src/protocols.c | 2 +- src/python.c | 6 +++--- src/redis.c | 6 +++--- src/routeros.c | 8 +++---- src/rrdcached.c | 14 ++++++------ src/rrdtool.c | 22 +++++++++---------- src/sigrok.c | 2 +- src/smart.c | 2 +- src/snmp.c | 16 +++++++------- src/snmp_agent.c | 16 +++++++------- src/threshold.c | 22 +++++++++---------- src/utils/cmds/cmds_test.c | 2 +- src/utils/common/common.c | 16 ++++++++++++++ src/utils/common/common.h | 3 +++ src/utils/config_cores/config_cores.c | 4 ++-- src/utils/db_query/db_query.c | 2 +- src/utils/dns/dns.c | 6 +++--- src/utils/dpdk/dpdk.c | 10 ++++----- src/utils/format_graphite/format_graphite_test.c | 2 +- src/utils/format_stackdriver/format_stackdriver.c | 12 +++++------ src/utils/gce/gce.c | 4 ++-- src/utils/oauth/oauth.c | 10 ++++----- src/utils/ovs/ovs.c | 4 ++-- src/utils/rrdcreate/rrdcreate.c | 14 ++++++------ src/varnish.c | 4 ++-- src/virt.c | 18 ++++++++-------- src/write_kafka.c | 4 ++-- src/write_prometheus.c | 18 ++++++++-------- src/write_redis.c | 6 +++--- src/write_riemann.c | 12 +++++------ src/write_stackdriver.c | 10 ++++----- src/zfs_arc.c | 2 +- 67 files changed, 302 insertions(+), 266 deletions(-) diff --git a/src/aggregation.c b/src/aggregation.c index 089ff1da..c37caeb5 100644 --- a/src/aggregation.c +++ b/src/aggregation.c @@ -198,13 +198,13 @@ static int agg_instance_create_name(agg_instance_t *inst, /* {{{ */ sstrncpy(inst->ident.plugin_instance, AGG_FUNC_PLACEHOLDER, sizeof(inst->ident.plugin_instance)); else if (strcmp("", tmp_plugin) != 0) - snprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance), + ssnprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance), "%s-%s", tmp_plugin, AGG_FUNC_PLACEHOLDER); else if (strcmp("", tmp_plugin_instance) != 0) - snprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance), + ssnprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance), "%s-%s", tmp_plugin_instance, AGG_FUNC_PLACEHOLDER); else - snprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance), + ssnprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance), "%s-%s-%s", tmp_plugin, tmp_plugin_instance, AGG_FUNC_PLACEHOLDER); } diff --git a/src/amqp.c b/src/amqp.c index 9eb51653..4c9ea0fd 100644 --- a/src/amqp.c +++ b/src/amqp.c @@ -217,23 +217,23 @@ static char *camqp_strerror(camqp_config_t *conf, /* {{{ */ if (r.reply.id == AMQP_CONNECTION_CLOSE_METHOD) { amqp_connection_close_t *m = r.reply.decoded; char *tmp = camqp_bytes_cstring(&m->reply_text); - snprintf(buffer, buffer_size, "Server connection error %d: %s", + ssnprintf(buffer, buffer_size, "Server connection error %d: %s", m->reply_code, tmp); sfree(tmp); } else if (r.reply.id == AMQP_CHANNEL_CLOSE_METHOD) { amqp_channel_close_t *m = r.reply.decoded; char *tmp = camqp_bytes_cstring(&m->reply_text); - snprintf(buffer, buffer_size, "Server channel error %d: %s", + ssnprintf(buffer, buffer_size, "Server channel error %d: %s", m->reply_code, tmp); sfree(tmp); } else { - snprintf(buffer, buffer_size, "Server error method %#" PRIx32, + ssnprintf(buffer, buffer_size, "Server error method %#" PRIx32, r.reply.id); } break; default: - snprintf(buffer, buffer_size, "Unknown reply type %i", (int)r.reply_type); + ssnprintf(buffer, buffer_size, "Unknown reply type %i", (int)r.reply_type); } return buffer; @@ -748,7 +748,7 @@ static int camqp_write(const data_set_t *ds, const value_list_t *vl, /* {{{ */ if (conf->routing_key != NULL) { sstrncpy(routing_key, conf->routing_key, sizeof(routing_key)); } else { - snprintf(routing_key, sizeof(routing_key), "collectd/%s/%s/%s/%s/%s", + ssnprintf(routing_key, sizeof(routing_key), "collectd/%s/%s/%s/%s/%s", vl->host, vl->plugin, vl->plugin_instance, vl->type, vl->type_instance); @@ -970,7 +970,7 @@ static int camqp_config_connection(oconfig_item_t *ci, /* {{{ */ if (publish) { char cbname[128]; - snprintf(cbname, sizeof(cbname), "amqp/%s", conf->name); + ssnprintf(cbname, sizeof(cbname), "amqp/%s", conf->name); status = plugin_register_write(cbname, camqp_write, diff --git a/src/amqp1.c b/src/amqp1.c index a7fd26be..11ff7c6b 100644 --- a/src/amqp1.c +++ b/src/amqp1.c @@ -624,12 +624,12 @@ static int amqp1_config_instance(oconfig_item_t *ci) /* {{{ */ return status; } else { char tpname[DATA_MAX_NAME_LEN]; - status = snprintf(tpname, sizeof(tpname), "amqp1/%s", instance->name); + status = ssnprintf(tpname, sizeof(tpname), "amqp1/%s", instance->name); if ((status < 0) || (size_t)status >= sizeof(tpname)) { ERROR("amqp1 plugin: Instance name would have been truncated."); return -1; } - status = snprintf(instance->send_to, sizeof(instance->send_to), "/%s/%s", + status = ssnprintf(instance->send_to, sizeof(instance->send_to), "/%s/%s", transport->address, instance->name); if ((status < 0) || (size_t)status >= sizeof(instance->send_to)) { ERROR("amqp1 plugin: send_to address would have been truncated."); diff --git a/src/aquaero.c b/src/aquaero.c index dfa2804d..fe75afe9 100644 --- a/src/aquaero.c +++ b/src/aquaero.c @@ -81,7 +81,7 @@ static void aquaero_submit_array(const char *type, if (value_array[i] == AQ5_FLOAT_UNDEF) continue; - snprintf(type_instance, sizeof(type_instance), "%s%d", type_instance_prefix, + ssnprintf(type_instance, sizeof(type_instance), "%s%d", type_instance_prefix, i + 1); aquaero_submit(type, type_instance, value_array[i]); } @@ -130,7 +130,7 @@ static int aquaero_read(void) { (aq_data.fan_vrm_temp[i] != AQ5_FLOAT_UNDEF)) continue; - snprintf(type_instance, sizeof(type_instance), "fan%d", i + 1); + ssnprintf(type_instance, sizeof(type_instance), "fan%d", i + 1); aquaero_submit("fanspeed", type_instance, aq_data.fan_rpm[i]); aquaero_submit("percent", type_instance, aq_data.fan_duty[i]); @@ -139,7 +139,7 @@ static int aquaero_read(void) { /* Report the voltage reglator module (VRM) temperature with a * different type instance. */ - snprintf(type_instance, sizeof(type_instance), "fan%d-vrm", i + 1); + ssnprintf(type_instance, sizeof(type_instance), "fan%d-vrm", i + 1); aquaero_submit("temperature", type_instance, aq_data.fan_vrm_temp[i]); } diff --git a/src/ascent.c b/src/ascent.c index e5589bf6..4006eb05 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -499,7 +499,7 @@ static int ascent_init(void) /* {{{ */ static char credentials[1024]; int status; - status = snprintf(credentials, sizeof(credentials), "%s:%s", user, + status = ssnprintf(credentials, sizeof(credentials), "%s:%s", user, (pass == NULL) ? "" : pass); if ((status < 0) || ((size_t)status >= sizeof(credentials))) { ERROR("ascent plugin: ascent_init: Returning an error because the " diff --git a/src/ceph.c b/src/ceph.c index 19a09d86..67c4c27d 100644 --- a/src/ceph.c +++ b/src/ceph.c @@ -990,7 +990,7 @@ static int cconn_connect(struct cconn *io) { return err; } address.sun_family = AF_UNIX; - snprintf(address.sun_path, sizeof(address.sun_path), "%s", io->d->asok_path); + ssnprintf(address.sun_path, sizeof(address.sun_path), "%s", io->d->asok_path); RETRY_ON_EINTR(err, connect(fd, (struct sockaddr *)&address, sizeof(struct sockaddr_un))); if (err < 0) { @@ -1153,7 +1153,7 @@ static ssize_t cconn_handle_event(struct cconn *io) { return -EDOM; case CSTATE_WRITE_REQUEST: { char cmd[32]; - snprintf(cmd, sizeof(cmd), "%s%d%s", "{ \"prefix\": \"", io->request_type, + ssnprintf(cmd, sizeof(cmd), "%s%d%s", "{ \"prefix\": \"", io->request_type, "\" }\n"); size_t cmd_len = strlen(cmd); RETRY_ON_EINTR( diff --git a/src/collectdctl.c b/src/collectdctl.c index 54c8081e..f7739a14 100644 --- a/src/collectdctl.c +++ b/src/collectdctl.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -80,6 +81,22 @@ extern char *optarg; extern int optind; +/* ssnprintf returns zero on success, one if truncation occurred + and a negative integer onerror. */ +static int _ssnprintf(char *str, size_t sz, const char *format, ...) { + va_list ap; + va_start(ap, format); + + int ret = vsnprintf(str, sz, format, ap); + + va_end(ap); + + if (ret < 0) { + return ret; + } + return (size_t)ret >= sz; +} /* int _ssnprintf */ + __attribute__((noreturn)) static void exit_usage(const char *name, int status) { fprintf( (status == 0) ? stdout : stderr, @@ -166,7 +183,7 @@ static int parse_identifier(lcc_connection_t *c, const char *value, } hostname[sizeof(hostname) - 1] = '\0'; - snprintf(ident_str, sizeof(ident_str), "%s/%s", hostname, value); + _ssnprintf(ident_str, sizeof(ident_str), "%s/%s", hostname, value); ident_str[sizeof(ident_str) - 1] = '\0'; } else { strncpy(ident_str, value, sizeof(ident_str)); @@ -543,7 +560,7 @@ int main(int argc, char **argv) { switch (opt) { case 's': - snprintf(address, sizeof(address), "unix:%s", optarg); + _ssnprintf(address, sizeof(address), "unix:%s", optarg); address[sizeof(address) - 1] = '\0'; break; case 'h': diff --git a/src/daemon/configfile.c b/src/daemon/configfile.c index 735be83d..0dad59f6 100644 --- a/src/daemon/configfile.c +++ b/src/daemon/configfile.c @@ -200,7 +200,7 @@ static int dispatch_global_option(const oconfig_item_t *ci) { return global_option_set(ci->key, ci->values[0].value.string, 0); else if (ci->values[0].type == OCONFIG_TYPE_NUMBER) { char tmp[128]; - snprintf(tmp, sizeof(tmp), "%lf", ci->values[0].value.number); + ssnprintf(tmp, sizeof(tmp), "%lf", ci->values[0].value.number); return global_option_set(ci->key, tmp, 0); } else if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN) { if (ci->values[0].value.boolean) @@ -311,12 +311,12 @@ static int dispatch_value_plugin(const char *plugin, oconfig_item_t *ci) { if (ci->values[i].type == OCONFIG_TYPE_STRING) status = - snprintf(buffer_ptr, buffer_free, " %s", ci->values[i].value.string); + 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", ci->values[i].value.number); + 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 ((status < 0) || (status >= buffer_free)) @@ -666,7 +666,7 @@ static oconfig_item_t *cf_read_dir(const char *dir, const char *pattern, if ((de->d_name[0] == '.') || (de->d_name[0] == 0)) continue; - status = snprintf(name, sizeof(name), "%s/%s", dir, de->d_name); + status = ssnprintf(name, sizeof(name), "%s/%s", dir, de->d_name); if ((status < 0) || ((size_t)status >= sizeof(name))) { ERROR("configfile: Not including `%s/%s' because its" " name is too long.", @@ -1235,7 +1235,7 @@ int cf_util_get_service(const oconfig_item_t *ci, char **ret_string) /* {{{ */ P_ERROR("cf_util_get_service: Out of memory."); return -1; } - snprintf(service, 6, "%i", port); + ssnprintf(service, 6, "%i", port); sfree(*ret_string); *ret_string = service; diff --git a/src/disk.c b/src/disk.c index e73a5c08..9976cfda 100644 --- a/src/disk.c +++ b/src/disk.c @@ -493,10 +493,10 @@ static int disk_read(void) { sstrncpy(disk_name, props_disk_name_bsd, sizeof(disk_name)); else { ERROR("disk plugin: can't find bsd disk name."); - snprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor); + ssnprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor); } } else - snprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor); + ssnprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor); DEBUG("disk plugin: disk_name = \"%s\"", disk_name); diff --git a/src/dpdkevents.c b/src/dpdkevents.c index 4cdf01df..a580a3a5 100644 --- a/src/dpdkevents.c +++ b/src/dpdkevents.c @@ -511,16 +511,16 @@ static int dpdk_events_link_status_dispatch(dpdk_helper_ctx_t *phc) { char dev_name[DATA_MAX_NAME_LEN]; if (ec->config.link_status.port_name[i][0] != 0) { - snprintf(dev_name, sizeof(dev_name), "%s", + ssnprintf(dev_name, sizeof(dev_name), "%s", ec->config.link_status.port_name[i]); } else { - snprintf(dev_name, sizeof(dev_name), "port.%d", i); + ssnprintf(dev_name, sizeof(dev_name), "port.%d", i); } if (ec->config.link_status.notify) { int sev = ec->link_info[i].link_status ? NOTIF_OKAY : NOTIF_WARNING; char msg[DATA_MAX_NAME_LEN]; - snprintf(msg, sizeof(msg), "Link Status: %s", + ssnprintf(msg, sizeof(msg), "Link Status: %s", ec->link_info[i].link_status ? "UP" : "DOWN"); dpdk_events_notification_dispatch(sev, dev_name, ec->link_info[i].read_time, msg); @@ -557,7 +557,7 @@ static void dpdk_events_keep_alive_dispatch(dpdk_helper_ctx_t *phc) { } char core_name[DATA_MAX_NAME_LEN]; - snprintf(core_name, sizeof(core_name), "lcore%u", i); + ssnprintf(core_name, sizeof(core_name), "lcore%u", i); if (!ec->config.keep_alive.send_updated || (ec->core_info[i].lcore_state != @@ -572,34 +572,34 @@ static void dpdk_events_keep_alive_dispatch(dpdk_helper_ctx_t *phc) { switch (ec->config.keep_alive.shm->core_state[i]) { case RTE_KA_STATE_ALIVE: sev = NOTIF_OKAY; - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: ALIVE", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: ALIVE", i); break; case RTE_KA_STATE_MISSING: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: MISSING", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: MISSING", i); sev = NOTIF_WARNING; break; case RTE_KA_STATE_DEAD: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DEAD", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DEAD", i); sev = NOTIF_FAILURE; break; case RTE_KA_STATE_UNUSED: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNUSED", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNUSED", i); sev = NOTIF_OKAY; break; case RTE_KA_STATE_GONE: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: GONE", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: GONE", i); sev = NOTIF_FAILURE; break; case RTE_KA_STATE_DOZING: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DOZING", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DOZING", i); sev = NOTIF_OKAY; break; case RTE_KA_STATE_SLEEP: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: SLEEP", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: SLEEP", i); sev = NOTIF_OKAY; break; default: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNKNOWN", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNKNOWN", i); sev = NOTIF_FAILURE; } diff --git a/src/dpdkstat.c b/src/dpdkstat.c index 0005d091..ae93e53b 100644 --- a/src/dpdkstat.c +++ b/src/dpdkstat.c @@ -395,9 +395,9 @@ static int dpdk_stats_counters_dispatch(dpdk_helper_ctx_t *phc) { char dev_name[64]; if (ctx->config.port_name[i][0] != 0) { - snprintf(dev_name, sizeof(dev_name), "%s", ctx->config.port_name[i]); + ssnprintf(dev_name, sizeof(dev_name), "%s", ctx->config.port_name[i]); } else { - snprintf(dev_name, sizeof(dev_name), "port.%d", i); + ssnprintf(dev_name, sizeof(dev_name), "port.%d", i); } DEBUG(" === Dispatch stats for port %d (name=%s; stats_count=%d)", i, diff --git a/src/gmond.c b/src/gmond.c index b14dee3b..132c138d 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -397,7 +397,7 @@ static staging_entry_t *staging_entry_get(const char *host, /* {{{ */ if (staging_tree == NULL) return NULL; - snprintf(key, sizeof(key), "%s/%s/%s", host, type, + ssnprintf(key, sizeof(key), "%s/%s/%s", host, type, (type_instance != NULL) ? type_instance : ""); se = NULL; diff --git a/src/intel_rdt.c b/src/intel_rdt.c index a68620ef..8d5ce612 100644 --- a/src/intel_rdt.c +++ b/src/intel_rdt.c @@ -105,7 +105,7 @@ static void rdt_submit_derive(const char *cgroup, const char *type, vl.values_len = 1; sstrncpy(vl.plugin, RDT_PLUGIN, sizeof(vl.plugin)); - snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup); + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup); sstrncpy(vl.type, type, sizeof(vl.type)); if (type_instance) sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); @@ -121,7 +121,7 @@ static void rdt_submit_gauge(const char *cgroup, const char *type, vl.values_len = 1; sstrncpy(vl.plugin, RDT_PLUGIN, sizeof(vl.plugin)); - snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup); + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s", cgroup); sstrncpy(vl.type, type, sizeof(vl.type)); if (type_instance) sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); @@ -144,7 +144,7 @@ static void rdt_dump_cgroups(void) { memset(cores, 0, sizeof(cores)); for (size_t j = 0; j < cgroup->num_cores; j++) { - snprintf(cores + strlen(cores), sizeof(cores) - strlen(cores) - 1, " %d", + ssnprintf(cores + strlen(cores), sizeof(cores) - strlen(cores) - 1, " %d", cgroup->cores[j]); } @@ -171,7 +171,7 @@ static void rdt_dump_ngroups(void) { for (size_t i = 0; i < g_rdt->num_ngroups; i++) { memset(names, 0, sizeof(names)); for (size_t j = 0; j < g_rdt->ngroups[i].num_names; j++) - snprintf(names + strlen(names), sizeof(names) - strlen(names) - 1, " %s", + ssnprintf(names + strlen(names), sizeof(names) - strlen(names) - 1, " %s", g_rdt->ngroups[i].names[j]); DEBUG(RDT_PLUGIN ": group[%d]:", (int)i); @@ -249,7 +249,7 @@ static void rdt_dump_pids_data(void) { for (size_t j = 0; j < g_rdt->ngroups[i].num_names; ++j) { pids_list_t *list = g_rdt->ngroups[i].proc_pids[j]->curr; for (size_t k = 0; k < list->size; k++) - snprintf(pids + strlen(pids), sizeof(pids) - strlen(pids) - 1, " %u", + ssnprintf(pids + strlen(pids), sizeof(pids) - strlen(pids) - 1, " %u", list->pids[k]); } DEBUG(RDT_PLUGIN ": [%s] %s", g_rdt->ngroups[i].desc, pids); @@ -922,7 +922,7 @@ static int rdt_default_cgroups(void) { cgroup->num_cores = 1; cgroup->cores[0] = i; - snprintf(desc, sizeof(desc), "%d", g_rdt->pqos_cpu->cores[i].lcore); + ssnprintf(desc, sizeof(desc), "%d", g_rdt->pqos_cpu->cores[i].lcore); cgroup->desc = strdup(desc); if (cgroup->desc == NULL) { ERROR(RDT_PLUGIN ": Error allocating core group description"); diff --git a/src/interface.c b/src/interface.c index 0e139708..f17dbc4a 100644 --- a/src/interface.c +++ b/src/interface.c @@ -297,7 +297,7 @@ static int interface_read(void) { continue; if (unique_name) - snprintf(iname, sizeof(iname), "%s_%d_%s", ksp[i]->ks_module, + ssnprintf(iname, sizeof(iname), "%s_%d_%s", ksp[i]->ks_module, ksp[i]->ks_instance, ksp[i]->ks_name); else sstrncpy(iname, ksp[i]->ks_name, sizeof(iname)); diff --git a/src/ipmi.c b/src/ipmi.c index d78ffa95..ed6c088e 100644 --- a/src/ipmi.c +++ b/src/ipmi.c @@ -111,7 +111,7 @@ static void c_ipmi_error(c_ipmi_instance_t *st, const char *func, int status) { } if (errbuf[0] == 0) { - snprintf(errbuf, sizeof(errbuf), "Unknown error %#x", status); + ssnprintf(errbuf, sizeof(errbuf), "Unknown error %#x", status); } errbuf[sizeof(errbuf) - 1] = '\0'; @@ -201,7 +201,7 @@ static void sensor_read_handler(ipmi_sensor_t *sensor, int err, sstrncpy(n.type_instance, list_item->type_instance, sizeof(n.type_instance)); sstrncpy(n.type, list_item->sensor_type, sizeof(n.type)); - snprintf(n.message, sizeof(n.message), "sensor %s not present", + ssnprintf(n.message, sizeof(n.message), "sensor %s not present", list_item->sensor_name); plugin_dispatch_notification(&n); @@ -254,7 +254,7 @@ static void sensor_read_handler(ipmi_sensor_t *sensor, int err, sstrncpy(n.type_instance, list_item->type_instance, sizeof(n.type_instance)); sstrncpy(n.type, list_item->sensor_type, sizeof(n.type)); - snprintf(n.message, sizeof(n.message), "sensor %s present", + ssnprintf(n.message, sizeof(n.message), "sensor %s present", list_item->sensor_name); plugin_dispatch_notification(&n); @@ -313,7 +313,7 @@ static void sensor_get_name(ipmi_sensor_t *sensor, char *buffer, int buf_len) { temp[sizeof(temp) - 1] = '\0'; if (entity_id_string != NULL && strlen(temp)) - snprintf(sensor_name, sizeof(sensor_name), "%s %s", temp, entity_id_string); + ssnprintf(sensor_name, sizeof(sensor_name), "%s %s", temp, entity_id_string); else if (entity_id_string != NULL) sstrncpy(sensor_name, entity_id_string, sizeof(sensor_name)); else @@ -338,7 +338,7 @@ static void sensor_get_name(ipmi_sensor_t *sensor, char *buffer, int buf_len) { sensor_id_ptr = strstr(temp, "("); if (sensor_id_ptr != NULL) { /* `sensor_id_ptr' now points to "(123)". */ - snprintf(sensor_name, sizeof(sensor_name), "%s %s", sensor_name_ptr, + ssnprintf(sensor_name, sizeof(sensor_name), "%s %s", sensor_name_ptr, sensor_id_ptr); } /* else: don't touch sensor_name. */ @@ -493,7 +493,7 @@ static int sensor_list_add(c_ipmi_instance_t *st, ipmi_sensor_t *sensor) { /* if sensor provides the percentage value, use "percent" collectd type and add the `percent` to the type instance of the reported value */ if (ipmi_sensor_get_percentage(sensor)) { - snprintf(list_item->type_instance, sizeof(list_item->type_instance), + ssnprintf(list_item->type_instance, sizeof(list_item->type_instance), "percent-%s", sensor_name_ptr); type = "percent"; } else { @@ -514,7 +514,7 @@ static int sensor_list_add(c_ipmi_instance_t *st, ipmi_sensor_t *sensor) { sstrncpy(n.type_instance, list_item->type_instance, sizeof(n.type_instance)); sstrncpy(n.type, list_item->sensor_type, sizeof(n.type)); - snprintf(n.message, sizeof(n.message), "sensor %s added", + ssnprintf(n.message, sizeof(n.message), "sensor %s added", list_item->sensor_name); plugin_dispatch_notification(&n); @@ -561,7 +561,7 @@ static int sensor_list_remove(c_ipmi_instance_t *st, ipmi_sensor_t *sensor) { sstrncpy(n.type_instance, list_item->type_instance, sizeof(n.type_instance)); sstrncpy(n.type, list_item->sensor_type, sizeof(n.type)); - snprintf(n.message, sizeof(n.message), "sensor %s removed", + ssnprintf(n.message, sizeof(n.message), "sensor %s removed", list_item->sensor_name); plugin_dispatch_notification(&n); @@ -674,11 +674,11 @@ static int sensor_threshold_event_handler( ipmi_get_reading_name(event_type, sensor_type, offset); sensor_get_name(sensor, n.type_instance, sizeof(n.type_instance)); if (value_present != IPMI_NO_VALUES_PRESENT) - snprintf(n.message, sizeof(n.message), + ssnprintf(n.message, sizeof(n.message), "sensor %s received event: %s, value is %f", n.type_instance, event_state, value); else - snprintf(n.message, sizeof(n.message), + ssnprintf(n.message, sizeof(n.message), "sensor %s received event: %s, value not provided", n.type_instance, event_state); @@ -699,7 +699,7 @@ static int sensor_threshold_event_handler( /* both values present, so fall-through to add raw value too */ case IPMI_RAW_VALUE_PRESENT: { char buf[DATA_MAX_NAME_LEN] = {0}; - snprintf(buf, sizeof(buf), "0x%2.2x", raw_value); + ssnprintf(buf, sizeof(buf), "0x%2.2x", raw_value); plugin_notification_meta_add_string(&n, "raw", buf); } break; default: @@ -741,7 +741,7 @@ static int sensor_discrete_event_handler(ipmi_sensor_t *sensor, const char *event_state = ipmi_get_reading_name(event_type, sensor_type, offset); sensor_get_name(sensor, n.type_instance, sizeof(n.type_instance)); - snprintf(n.message, sizeof(n.message), "sensor %s received event: %s", + ssnprintf(n.message, sizeof(n.message), "sensor %s received event: %s", n.type_instance, event_state); DEBUG("Discrete event received for sensor %s", n.type_instance); @@ -1253,7 +1253,7 @@ static int c_ipmi_init(void) { /* The `st->name` is used as "domain name" for ipmi_open_domain(). * That value should be unique, so we do plugin_register_complex_read() * at first as it checks the uniqueness. */ - snprintf(callback_name, sizeof(callback_name), "ipmi/%s", st->name); + ssnprintf(callback_name, sizeof(callback_name), "ipmi/%s", st->name); user_data_t ud = { .data = st, diff --git a/src/iptables.c b/src/iptables.c index e1d83dfc..8bc71ccb 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -221,7 +221,7 @@ static int submit6_match(const struct ip6t_entry_match *match, sstrncpy(vl.plugin, "ip6tables", sizeof(vl.plugin)); - status = snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s", + 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; @@ -230,7 +230,7 @@ static int submit6_match(const struct ip6t_entry_match *match, 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), "%i", + ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%i", chain->rule.num); else sstrncpy(vl.type_instance, (char *)match->data, sizeof(vl.type_instance)); @@ -269,7 +269,7 @@ static int submit_match(const struct ipt_entry_match *match, sstrncpy(vl.plugin, "iptables", sizeof(vl.plugin)); - status = snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s", + 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; @@ -278,7 +278,7 @@ static int submit_match(const struct ipt_entry_match *match, 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), "%i", + ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%i", chain->rule.num); else sstrncpy(vl.type_instance, (char *)match->data, sizeof(vl.type_instance)); diff --git a/src/lpar.c b/src/lpar.c index dc3739b8..1c8685ed 100644 --- a/src/lpar.c +++ b/src/lpar.c @@ -224,10 +224,10 @@ static int lpar_read(void) { if (pool_busy_cpus < 0.0) pool_busy_cpus = 0.0; - snprintf(typinst, sizeof(typinst), "pool-%X-busy", lparstats.pool_id); + ssnprintf(typinst, sizeof(typinst), "pool-%X-busy", lparstats.pool_id); lpar_submit(typinst, pool_busy_cpus); - snprintf(typinst, sizeof(typinst), "pool-%X-idle", lparstats.pool_id); + ssnprintf(typinst, sizeof(typinst), "pool-%X-idle", lparstats.pool_id); lpar_submit(typinst, pool_idle_cpus); } diff --git a/src/lua.c b/src/lua.c index 9a1ceed7..bcefafc1 100644 --- a/src/lua.c +++ b/src/lua.c @@ -278,7 +278,7 @@ static int lua_cb_register_generic(lua_State *L, int type) /* {{{ */ char subname[DATA_MAX_NAME_LEN]; if (!lua_isfunction(L, 1) && lua_isstring(L, 1)) { const char *fname = lua_tostring(L, 1); - snprintf(subname, sizeof(subname), "%s()", fname); + ssnprintf(subname, sizeof(subname), "%s()", fname); lua_getglobal(L, fname); // Push function into stack lua_remove(L, 1); // Remove string from stack @@ -288,7 +288,7 @@ static int lua_cb_register_generic(lua_State *L, int type) /* {{{ */ } else { lua_getfield(L, LUA_REGISTRYINDEX, "collectd:callback_num"); int tmp = lua_tointeger(L, -1); - snprintf(subname, sizeof(subname), "callback_%d", tmp); + ssnprintf(subname, sizeof(subname), "callback_%d", tmp); lua_pop(L, 1); // Remove old value from stack lua_pushinteger(L, tmp + 1); lua_setfield(L, LUA_REGISTRYINDEX, "collectd:callback_num"); // pops value @@ -298,7 +298,7 @@ static int lua_cb_register_generic(lua_State *L, int type) /* {{{ */ lua_getfield(L, LUA_REGISTRYINDEX, "collectd:script_path"); char function_name[DATA_MAX_NAME_LEN]; - snprintf(function_name, sizeof(function_name), "lua/%s/%s", + ssnprintf(function_name, sizeof(function_name), "lua/%s/%s", lua_tostring(L, -1), subname); lua_pop(L, 1); @@ -530,7 +530,7 @@ static int lua_config_script(const oconfig_item_t *ci) /* {{{ */ if (base_path[0] == '\0') sstrncpy(abs_path, rel_path, sizeof(abs_path)); else - snprintf(abs_path, sizeof(abs_path), "%s/%s", base_path, rel_path); + ssnprintf(abs_path, sizeof(abs_path), "%s/%s", base_path, rel_path); DEBUG("Lua plugin: abs_path = \"%s\";", abs_path); diff --git a/src/lvm.c b/src/lvm.c index c30489cb..6163ff83 100644 --- a/src/lvm.c +++ b/src/lvm.c @@ -81,7 +81,7 @@ static void report_lv_utilization(lv_t lv, char const *vg_name, return; used_bytes = lv_size * (used_percent_unscaled * PERCENT_SCALE_FACTOR); - snprintf(plugin_instance, sizeof(plugin_instance), "%s-%s", vg_name, lv_name); + ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-%s", vg_name, lv_name); lvm_submit(plugin_instance, "used", used_bytes); lvm_submit(plugin_instance, "free", lv_size - used_bytes); } diff --git a/src/mic.c b/src/mic.c index 6924eaf7..70765574 100644 --- a/src/mic.c +++ b/src/mic.c @@ -132,7 +132,7 @@ static void mic_submit_memory_use(int micnumber, const char *type_instance, vl.values_len = 1; strncpy(vl.plugin, "mic", sizeof(vl.plugin)); - snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber); + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber); strncpy(vl.type, "memory", sizeof(vl.type)); strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); @@ -164,7 +164,7 @@ static void mic_submit_temp(int micnumber, const char *type, gauge_t value) { vl.values_len = 1; strncpy(vl.plugin, "mic", sizeof(vl.plugin)); - snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber); + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber); strncpy(vl.type, "temperature", sizeof(vl.type)); strncpy(vl.type_instance, type, sizeof(vl.type_instance)); @@ -206,9 +206,9 @@ static void mic_submit_cpu(int micnumber, const char *type_instance, int core, strncpy(vl.plugin, "mic", sizeof(vl.plugin)); if (core < 0) /* global aggregation */ - snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber); + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber); else /* per-core statistics */ - snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i-cpu-%i", + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i-cpu-%i", micnumber, core); strncpy(vl.type, "cpu", sizeof(vl.type)); strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); @@ -258,7 +258,7 @@ static void mic_submit_power(int micnumber, const char *type, vl.values_len = 1; strncpy(vl.plugin, "mic", sizeof(vl.plugin)); - snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber); + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber); strncpy(vl.type, type, sizeof(vl.type)); strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); diff --git a/src/modbus.c b/src/modbus.c index 04232c35..5b2509b4 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -259,7 +259,7 @@ static int mb_submit(mb_host_t *host, mb_slave_t *slave, /* {{{ */ return EINVAL; if (slave->instance[0] == 0) - snprintf(slave->instance, sizeof(slave->instance), "slave_%i", slave->id); + ssnprintf(slave->instance, sizeof(slave->instance), "slave_%i", slave->id); vl.values = &value; vl.values_len = 1; @@ -1072,7 +1072,7 @@ static int mb_config_add_host(oconfig_item_t *ci) /* {{{ */ if (status == 0) { char name[1024]; - snprintf(name, sizeof(name), "modbus-%s", host->host); + ssnprintf(name, sizeof(name), "modbus-%s", host->host); plugin_register_complex_read(/* group = */ NULL, name, /* callback = */ mb_read, diff --git a/src/mqtt.c b/src/mqtt.c index 630114e4..a44f4c82 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -462,7 +462,7 @@ static int format_topic(char *buf, size_t buf_len, data_set_t const *ds, if (status != 0) return status; - status = snprintf(buf, buf_len, "%s/%s", conf->topic_prefix, name); + status = ssnprintf(buf, buf_len, "%s/%s", conf->topic_prefix, name); if ((status < 0) || (((size_t)status) >= buf_len)) return ENOMEM; @@ -599,7 +599,7 @@ static int mqtt_config_publisher(oconfig_item_t *ci) { ERROR("mqtt plugin: Unknown config option: %s", child->key); } - snprintf(cb_name, sizeof(cb_name), "mqtt/%s", conf->name); + ssnprintf(cb_name, sizeof(cb_name), "mqtt/%s", conf->name); plugin_register_write(cb_name, mqtt_write, &(user_data_t){ .data = conf, diff --git a/src/mysql.c b/src/mysql.c index 7399fe21..5244d29c 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -218,7 +218,7 @@ static int mysql_config_database(oconfig_item_t *ci) /* {{{ */ (db->database != NULL) ? db->database : ""); if (db->instance != NULL) - snprintf(cb_name, sizeof(cb_name), "mysql-%s", db->instance); + ssnprintf(cb_name, sizeof(cb_name), "mysql-%s", db->instance); else sstrncpy(cb_name, "mysql", sizeof(cb_name)); @@ -500,14 +500,14 @@ static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) { if (((io == NULL) || (strcasecmp(io, "yes") != 0)) && (db->slave_io_running)) { n.severity = NOTIF_WARNING; - snprintf(n.message, sizeof(n.message), + ssnprintf(n.message, sizeof(n.message), "slave I/O thread not started or not connected to master"); plugin_dispatch_notification(&n); db->slave_io_running = false; } else if (((io != NULL) && (strcasecmp(io, "yes") == 0)) && (!db->slave_io_running)) { n.severity = NOTIF_OKAY; - snprintf(n.message, sizeof(n.message), + ssnprintf(n.message, sizeof(n.message), "slave I/O thread started and connected to master"); plugin_dispatch_notification(&n); db->slave_io_running = true; @@ -516,13 +516,13 @@ static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) { if (((sql == NULL) || (strcasecmp(sql, "yes") != 0)) && (db->slave_sql_running)) { n.severity = NOTIF_WARNING; - snprintf(n.message, sizeof(n.message), "slave SQL thread not started"); + ssnprintf(n.message, sizeof(n.message), "slave SQL thread not started"); plugin_dispatch_notification(&n); db->slave_sql_running = false; } else if (((sql != NULL) && (strcasecmp(sql, "yes") == 0)) && (!db->slave_sql_running)) { n.severity = NOTIF_OKAY; - snprintf(n.message, sizeof(n.message), "slave SQL thread started"); + ssnprintf(n.message, sizeof(n.message), "slave SQL thread started"); plugin_dispatch_notification(&n); db->slave_sql_running = true; } diff --git a/src/netapp.c b/src/netapp.c index 1b510d2a..b950acc4 100644 --- a/src/netapp.c +++ b/src/netapp.c @@ -773,7 +773,7 @@ static int submit_volume_perf_data(const char *hostname, /* {{{ */ if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL)) return -1; - snprintf(plugin_instance, sizeof(plugin_instance), "volume-%s", + ssnprintf(plugin_instance, sizeof(plugin_instance), "volume-%s", old_data->name); /* Check for and submit disk-octet values */ @@ -1404,7 +1404,7 @@ static int cna_submit_volume_usage_data(const char *hostname, /* {{{ */ uint64_t snap_reserve_free = v->snap_reserved; uint64_t snap_norm_used = v->snap_used; - snprintf(plugin_instance, sizeof(plugin_instance), "volume-%s", v->name); + ssnprintf(plugin_instance, sizeof(plugin_instance), "volume-%s", v->name); if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SNAP_USED | @@ -1498,11 +1498,11 @@ static int cna_change_volume_status(const char *hostname, /* {{{ */ if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) { n.severity = NOTIF_OKAY; - snprintf(n.message, sizeof(n.message), "Volume %s is now online.", v->name); + ssnprintf(n.message, sizeof(n.message), "Volume %s is now online.", v->name); v->flags &= ~IS_VOLUME_USAGE_OFFLINE; } else { n.severity = NOTIF_WARNING; - snprintf(n.message, sizeof(n.message), "Volume %s is now offline.", + ssnprintf(n.message, sizeof(n.message), "Volume %s is now offline.", v->name); v->flags |= IS_VOLUME_USAGE_OFFLINE; } @@ -1832,7 +1832,7 @@ static int cna_handle_quota_data(const host_config_t *host, /* {{{ */ if (volume_name == NULL) continue; - snprintf(plugin_instance, sizeof(plugin_instance), "quota-%s-%s", + ssnprintf(plugin_instance, sizeof(plugin_instance), "quota-%s-%s", volume_name, tree_name); value = na_child_get_uint64(elem_quota, "disk-used", UINT64_MAX); @@ -1945,7 +1945,7 @@ static int cna_handle_snapvault_data(const char *hostname, /* {{{ */ continue; /* possible TODO: make plugin instance configurable */ - snprintf(plugin_instance, sizeof(plugin_instance), "snapvault-%s", + ssnprintf(plugin_instance, sizeof(plugin_instance), "snapvault-%s", dest_path); submit_double(hostname, plugin_instance, /* type = */ "delay", NULL, (double)value, /* timestamp = */ 0, interval); @@ -2787,10 +2787,10 @@ static int cna_register_host(host_config_t *host) /* {{{ */ char cb_name[256]; if (host->vfiler) - snprintf(cb_name, sizeof(cb_name), "netapp-%s-%s", host->name, + ssnprintf(cb_name, sizeof(cb_name), "netapp-%s-%s", host->name, host->vfiler); else - snprintf(cb_name, sizeof(cb_name), "netapp-%s", host->name); + ssnprintf(cb_name, sizeof(cb_name), "netapp-%s", host->name); plugin_register_complex_read( /* group = */ NULL, cb_name, diff --git a/src/netlink.c b/src/netlink.c index 37c2e294..a3b40d49 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -509,7 +509,7 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { if (strcmp(tc_type, "filter") == 0) numberic_id = tm->tcm_parent; - snprintf(tc_inst, sizeof(tc_inst), "%s-%x:%x", kind, numberic_id >> 16, + ssnprintf(tc_inst, sizeof(tc_inst), "%s-%x:%x", kind, numberic_id >> 16, numberic_id & 0x0000FFFF); } @@ -541,7 +541,7 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { stats_submitted = true; - int r = snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, + int r = ssnprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst); if ((size_t)r >= sizeof(type_instance)) { ERROR("netlink plugin: type_instance truncated to %zu bytes, need %d", @@ -580,7 +580,7 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { if (!stats_submitted && ts != NULL) { char type_instance[DATA_MAX_NAME_LEN]; - int r = snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, + int r = ssnprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst); if ((size_t)r >= sizeof(type_instance)) { ERROR("netlink plugin: type_instance truncated to %zu bytes, need %d", diff --git a/src/nginx.c b/src/nginx.c index 7bb307a3..15e56fbc 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -122,7 +122,7 @@ static int init(void) { curl_easy_setopt(curl, CURLOPT_PASSWORD, (pass == NULL) ? "" : pass); #else static char credentials[1024]; - int status = snprintf(credentials, sizeof(credentials), "%s:%s", user, + int status = ssnprintf(credentials, sizeof(credentials), "%s:%s", user, pass == NULL ? "" : pass); if ((status < 0) || ((size_t)status >= sizeof(credentials))) { ERROR("nginx plugin: Credentials would have been truncated."); diff --git a/src/notify_desktop.c b/src/notify_desktop.c index 849b1d4c..520a2804 100644 --- a/src/notify_desktop.c +++ b/src/notify_desktop.c @@ -93,7 +93,7 @@ static int c_notify(const notification_t *n, timeout = fail_timeout; } - snprintf(summary, sizeof(summary), "collectd %s notification", + ssnprintf(summary, sizeof(summary), "collectd %s notification", (NOTIF_FAILURE == n->severity) ? "FAILURE" : (NOTIF_WARNING == n->severity) diff --git a/src/notify_email.c b/src/notify_email.c index dddb8b26..e620cf63 100644 --- a/src/notify_email.c +++ b/src/notify_email.c @@ -104,7 +104,7 @@ static void monitor_cb(const char *buf, int buflen, int writing, static int notify_email_init(void) { char server[MAXSTRING]; - snprintf(server, sizeof(server), "%s:%i", + ssnprintf(server, sizeof(server), "%s:%i", (smtp_host == NULL) ? DEFAULT_SMTP_HOST : smtp_host, smtp_port); pthread_mutex_lock(&session_lock); @@ -214,14 +214,14 @@ static int notify_email_notification(const notification_t *n, char *buf_ptr = buf; int buf_len = sizeof(buf); - snprintf(severity, sizeof(severity), "%s", + ssnprintf(severity, sizeof(severity), "%s", (n->severity == NOTIF_FAILURE) ? "FAILURE" : ((n->severity == NOTIF_WARNING) ? "WARNING" : ((n->severity == NOTIF_OKAY) ? "OKAY" : "UNKNOWN"))); - snprintf(subject, sizeof(subject), + ssnprintf(subject, sizeof(subject), (email_subject == NULL) ? DEFAULT_SMTP_SUBJECT : email_subject, severity, n->host); @@ -231,7 +231,7 @@ static int notify_email_notification(const notification_t *n, timestamp_str[sizeof(timestamp_str) - 1] = '\0'; /* Let's make RFC822 message text with \r\n EOLs */ - int status = snprintf(buf, buf_len, + int status = ssnprintf(buf, buf_len, "MIME-Version: 1.0\r\n" "Content-Type: text/plain; charset=\"US-ASCII\"\r\n" "Content-Transfer-Encoding: 8bit\r\n" @@ -248,7 +248,7 @@ static int notify_email_notification(const notification_t *n, #define APPEND(format, value) \ if ((buf_len > 0) && (strlen(value) > 0)) { \ - status = snprintf(buf_ptr, buf_len, format "\r\n", value); \ + status = ssnprintf(buf_ptr, buf_len, format "\r\n", value); \ if (status > 0) { \ buf_ptr += status; \ buf_len -= status; \ diff --git a/src/onewire.c b/src/onewire.c index a0a546b2..7153b0ad 100644 --- a/src/onewire.c +++ b/src/onewire.c @@ -297,7 +297,7 @@ static int cow_read_values(const char *path, const char *name, char file[4096]; char *endptr; - snprintf(file, sizeof(file), "%s/%s", path, + ssnprintf(file, sizeof(file), "%s/%s", path, family_info->features[i].filename); file[sizeof(file) - 1] = '\0'; @@ -348,11 +348,11 @@ static int cow_read_ds2409(const char *path) { char subpath[4096]; int status; - status = snprintf(subpath, sizeof(subpath), "%s/main", path); + status = ssnprintf(subpath, sizeof(subpath), "%s/main", path); if ((status > 0) && (status < (int)sizeof(subpath))) cow_read_bus(subpath); - status = snprintf(subpath, sizeof(subpath), "%s/aux", path); + status = ssnprintf(subpath, sizeof(subpath), "%s/aux", path); if ((status > 0) && (status < (int)sizeof(subpath))) cow_read_bus(subpath); @@ -384,9 +384,9 @@ static int cow_read_bus(const char *path) { dummy = NULL; if (strcmp("/", path) == 0) - status = snprintf(subpath, sizeof(subpath), "/%s", buffer_ptr); + status = ssnprintf(subpath, sizeof(subpath), "/%s", buffer_ptr); else - status = snprintf(subpath, sizeof(subpath), "%s/%s", path, buffer_ptr); + status = ssnprintf(subpath, sizeof(subpath), "%s/%s", path, buffer_ptr); if ((status <= 0) || (status >= (int)sizeof(subpath))) continue; diff --git a/src/openldap.c b/src/openldap.c index 5659c69f..7dc8f739 100644 --- a/src/openldap.c +++ b/src/openldap.c @@ -306,7 +306,7 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */ if ((olmbdb_list = ldap_get_values_len(st->ld, e, "olmBDBEntryCache")) != NULL) { olmbdb_data = *olmbdb_list[0]; - snprintf(typeinst, sizeof(typeinst), "bdbentrycache-%s", + ssnprintf(typeinst, sizeof(typeinst), "bdbentrycache-%s", nc_data.bv_val); cldap_submit_gauge("cache_size", typeinst, atoll(olmbdb_data.bv_val), st); @@ -316,7 +316,7 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */ if ((olmbdb_list = ldap_get_values_len(st->ld, e, "olmBDBDNCache")) != NULL) { olmbdb_data = *olmbdb_list[0]; - snprintf(typeinst, sizeof(typeinst), "bdbdncache-%s", nc_data.bv_val); + ssnprintf(typeinst, sizeof(typeinst), "bdbdncache-%s", nc_data.bv_val); cldap_submit_gauge("cache_size", typeinst, atoll(olmbdb_data.bv_val), st); ldap_value_free_len(olmbdb_list); @@ -325,7 +325,7 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */ if ((olmbdb_list = ldap_get_values_len(st->ld, e, "olmBDBIDLCache")) != NULL) { olmbdb_data = *olmbdb_list[0]; - snprintf(typeinst, sizeof(typeinst), "bdbidlcache-%s", + ssnprintf(typeinst, sizeof(typeinst), "bdbidlcache-%s", nc_data.bv_val); cldap_submit_gauge("cache_size", typeinst, atoll(olmbdb_data.bv_val), st); @@ -462,7 +462,7 @@ static int cldap_config_add(oconfig_item_t *ci) /* {{{ */ char callback_name[3 * DATA_MAX_NAME_LEN] = {0}; - snprintf(callback_name, sizeof(callback_name), "openldap/%s/%s", + ssnprintf(callback_name, sizeof(callback_name), "openldap/%s/%s", (st->host != NULL) ? st->host : hostname_g, (st->name != NULL) ? st->name : "default"); diff --git a/src/oracle.c b/src/oracle.c index 3f28110f..cebc7a2f 100644 --- a/src/oracle.c +++ b/src/oracle.c @@ -640,7 +640,7 @@ static int o_read_database(o_database_t *db) /* {{{ */ if ((status != OCI_SUCCESS) && (status != OCI_SUCCESS_WITH_INFO)) { char errfunc[256]; - snprintf(errfunc, sizeof(errfunc), "OCILogon(\"%s\")", db->connect_id); + ssnprintf(errfunc, sizeof(errfunc), "OCILogon(\"%s\")", db->connect_id); o_report_error("o_read_database", db->name, NULL, errfunc, oci_error); DEBUG("oracle plugin: OCILogon (%s): db->oci_service_context = %p;", diff --git a/src/ovs_events.c b/src/ovs_events.c index 0f9a57ca..49e08f58 100644 --- a/src/ovs_events.c +++ b/src/ovs_events.c @@ -158,7 +158,7 @@ static char *ovs_events_get_select_params() { return NULL; } opt_buff = new_buff; - int ret = snprintf(opt_buff + buff_off, buff_size - buff_off, option_fmt, + int ret = ssnprintf(opt_buff + buff_off, buff_size - buff_off, option_fmt, iface->name); if (ret < 0) { sfree(opt_buff); @@ -339,7 +339,7 @@ ovs_events_dispatch_notification(const ovs_events_iface_info_t *ifinfo) { } /* fill the notification data */ - snprintf(n.message, sizeof(n.message), + ssnprintf(n.message, sizeof(n.message), "link state of \"%s\" interface has been changed to \"%s\"", ifinfo->name, msg_link_status); sstrncpy(n.host, hostname_g, sizeof(n.host)); diff --git a/src/ovs_stats.c b/src/ovs_stats.c index da218b6f..4ec14f4f 100644 --- a/src/ovs_stats.c +++ b/src/ovs_stats.c @@ -394,16 +394,16 @@ static void ovs_stats_submit_port(port_list_t *port) { for (interface_list_t *iface = port->iface; iface != NULL; iface = iface->next) { - snprintf(key_str, sizeof(key_str), "uuid%d", i); + ssnprintf(key_str, sizeof(key_str), "uuid%d", i); meta_data_add_string(meta, key_str, iface->iface_uuid); if (strlen(iface->ex_vm_id)) { - snprintf(key_str, sizeof(key_str), "vm-uuid%d", i); + ssnprintf(key_str, sizeof(key_str), "vm-uuid%d", i); meta_data_add_string(meta, key_str, iface->ex_vm_id); } if (strlen(iface->ex_iface_id)) { - snprintf(key_str, sizeof(key_str), "iface-id%d", i); + ssnprintf(key_str, sizeof(key_str), "iface-id%d", i); meta_data_add_string(meta, key_str, iface->ex_iface_id); } @@ -411,7 +411,7 @@ static void ovs_stats_submit_port(port_list_t *port) { } } bridge_list_t *bridge = port->br; - snprintf(devname, sizeof(devname), "%s.%s", bridge->name, port->name); + ssnprintf(devname, sizeof(devname), "%s.%s", bridge->name, port->name); ovs_stats_submit_one(devname, "if_collisions", NULL, ovs_stats_get_port_stat_value(port, collisions), meta); ovs_stats_submit_two(devname, "if_dropped", NULL, diff --git a/src/perl.c b/src/perl.c index 09e6e5aa..0a4ae71d 100644 --- a/src/perl.c +++ b/src/perl.c @@ -863,9 +863,9 @@ static int oconfig_item2hv(pTHX_ oconfig_item_t *ci, 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; return buf; diff --git a/src/postgresql.c b/src/postgresql.c index 8e4328fa..466c0e3a 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -58,7 +58,7 @@ * is ignored. */ #define C_PSQL_PAR_APPEND(buf, buf_len, parameter, value) \ if ((0 < (buf_len)) && (NULL != (value)) && ('\0' != *(value))) { \ - int s = snprintf(buf, buf_len, " %s = '%s'", parameter, value); \ + int s = ssnprintf(buf, buf_len, " %s = '%s'", parameter, value); \ if (0 < s) { \ buf += s; \ buf_len -= s; \ @@ -323,7 +323,7 @@ static int c_psql_connect(c_psql_database_t *db) { if ((!db) || (!db->database)) return -1; - status = snprintf(buf, buf_len, "dbname = '%s'", db->database); + status = ssnprintf(buf, buf_len, "dbname = '%s'", db->database); if (0 < status) { buf += status; buf_len -= status; @@ -426,7 +426,7 @@ static PGresult *c_psql_exec_query_params(c_psql_database_t *db, udb_query_t *q, params[i] = db->user; break; case C_PSQL_PARAM_INTERVAL: - snprintf(interval, sizeof(interval), "%.3f", + ssnprintf(interval, sizeof(interval), "%.3f", CDTIME_T_TO_DOUBLE(plugin_get_interval())); params[i] = interval; break; @@ -632,7 +632,7 @@ static char *values_name_to_sqlarray(const data_set_t *ds, char *string, str_len = string_len; for (size_t i = 0; i < ds->ds_num; ++i) { - int status = snprintf(str_ptr, str_len, ",'%s'", ds->ds[i].name); + int status = ssnprintf(str_ptr, str_len, ",'%s'", ds->ds[i].name); if (status < 1) return NULL; @@ -670,9 +670,9 @@ static char *values_type_to_sqlarray(const data_set_t *ds, char *string, int status; if (store_rates) - status = snprintf(str_ptr, str_len, ",'gauge'"); + status = ssnprintf(str_ptr, str_len, ",'gauge'"); else - status = snprintf(str_ptr, str_len, ",'%s'", + status = ssnprintf(str_ptr, str_len, ",'%s'", DS_TYPE_TO_STRING(ds->ds[i].type)); if (status < 1) { @@ -725,7 +725,7 @@ static char *values_to_sqlarray(const data_set_t *ds, const value_list_t *vl, if (ds->ds[i].type == DS_TYPE_GAUGE) status = - snprintf(str_ptr, str_len, "," GAUGE_FORMAT, vl->values[i].gauge); + ssnprintf(str_ptr, str_len, "," GAUGE_FORMAT, vl->values[i].gauge); else if (store_rates) { if (rates == NULL) rates = uc_get_rate(ds, vl); @@ -735,14 +735,14 @@ static char *values_to_sqlarray(const data_set_t *ds, const value_list_t *vl, return NULL; } - status = snprintf(str_ptr, str_len, ",%lf", rates[i]); + status = ssnprintf(str_ptr, str_len, ",%lf", rates[i]); } else if (ds->ds[i].type == DS_TYPE_COUNTER) - status = snprintf(str_ptr, str_len, ",%" PRIu64, + status = ssnprintf(str_ptr, str_len, ",%" PRIu64, (uint64_t)vl->values[i].counter); else if (ds->ds[i].type == DS_TYPE_DERIVE) - status = snprintf(str_ptr, str_len, ",%" PRIi64, vl->values[i].derive); + status = ssnprintf(str_ptr, str_len, ",%" PRIi64, vl->values[i].derive); else if (ds->ds[i].type == DS_TYPE_ABSOLUTE) - status = snprintf(str_ptr, str_len, ",%" PRIu64, vl->values[i].absolute); + status = ssnprintf(str_ptr, str_len, ",%" PRIu64, vl->values[i].absolute); if (status < 1) { str_len = 0; @@ -940,7 +940,7 @@ static int c_psql_shutdown(void) { if (db->writers_num > 0) { char cb_name[DATA_MAX_NAME_LEN]; - snprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->database); + ssnprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->database); if (!had_flush) { plugin_unregister_flush("postgresql"); @@ -1199,7 +1199,7 @@ static int c_psql_config_database(oconfig_item_t *ci) { } } - snprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->instance); + ssnprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->instance); user_data_t ud = {.data = db, .free_func = c_psql_database_delete}; diff --git a/src/protocols.c b/src/protocols.c index 65b450c9..86fa795a 100644 --- a/src/protocols.c +++ b/src/protocols.c @@ -154,7 +154,7 @@ static int read_file(const char *path) { if (values_list != NULL) { char match_name[2 * DATA_MAX_NAME_LEN]; - snprintf(match_name, sizeof(match_name), "%s:%s", key_buffer, + ssnprintf(match_name, sizeof(match_name), "%s:%s", key_buffer, key_fields[i]); if (ignorelist_match(values_list, match_name)) diff --git a/src/python.c b/src/python.c index 9d47d701..5669f45a 100644 --- a/src/python.c +++ b/src/python.c @@ -285,7 +285,7 @@ static void cpy_build_name(char *buf, size_t size, PyObject *callback, PyObject *mod = NULL; if (name != NULL) { - snprintf(buf, size, "python.%s", name); + ssnprintf(buf, size, "python.%s", name); return; } @@ -294,14 +294,14 @@ static void cpy_build_name(char *buf, size_t size, PyObject *callback, module = cpy_unicode_or_bytes_to_string(&mod); if (module != NULL) { - snprintf(buf, size, "python.%s", module); + ssnprintf(buf, size, "python.%s", module); Py_XDECREF(mod); PyErr_Clear(); return; } Py_XDECREF(mod); - snprintf(buf, size, "python.%p", callback); + ssnprintf(buf, size, "python.%p", callback); PyErr_Clear(); } diff --git a/src/redis.c b/src/redis.c index 37dc8d68..12f68946 100644 --- a/src/redis.c +++ b/src/redis.c @@ -115,7 +115,7 @@ static int redis_node_add(redis_node_t *rn) /* {{{ */ redis_have_instances = true; char cb_name[sizeof("redis/") + DATA_MAX_NAME_LEN]; - snprintf(cb_name, sizeof(cb_name), "redis/%s", rn->name); + ssnprintf(cb_name, sizeof(cb_name), "redis/%s", rn->name); return plugin_register_complex_read( /* group = */ "redis", @@ -486,7 +486,7 @@ static int redis_db_stats(const char *node, char const *info_line) /* {{{ */ char *str; int i; - snprintf(field_name, sizeof(field_name), "db%d:keys=", db); + ssnprintf(field_name, sizeof(field_name), "db%d:keys=", db); str = strstr(info_line, field_name); if (!str) @@ -502,7 +502,7 @@ static int redis_db_stats(const char *node, char const *info_line) /* {{{ */ return -1; } - snprintf(db_id, sizeof(db_id), "%d", db); + ssnprintf(db_id, sizeof(db_id), "%d", db); redis_submit(node, "records", db_id, val); } return 0; diff --git a/src/routeros.c b/src/routeros.c index 70dd75ee..a0956377 100644 --- a/src/routeros.c +++ b/src/routeros.c @@ -150,7 +150,7 @@ static void submit_regtable(cr_data_t *rd, /* {{{ */ name = "default"; /*** RX ***/ - snprintf(type_instance, sizeof(type_instance), "%s-%s-rx", r->interface, + ssnprintf(type_instance, sizeof(type_instance), "%s-%s-rx", r->interface, name); cr_submit_gauge(rd, "bitrate", type_instance, (gauge_t)(1000000.0 * r->rx_rate)); @@ -159,7 +159,7 @@ static void submit_regtable(cr_data_t *rd, /* {{{ */ cr_submit_gauge(rd, "signal_quality", type_instance, (gauge_t)r->rx_ccq); /*** TX ***/ - snprintf(type_instance, sizeof(type_instance), "%s-%s-tx", r->interface, + ssnprintf(type_instance, sizeof(type_instance), "%s-%s-tx", r->interface, name); cr_submit_gauge(rd, "bitrate", type_instance, (gauge_t)(1000000.0 * r->tx_rate)); @@ -168,7 +168,7 @@ static void submit_regtable(cr_data_t *rd, /* {{{ */ cr_submit_gauge(rd, "signal_quality", type_instance, (gauge_t)r->tx_ccq); /*** RX / TX ***/ - snprintf(type_instance, sizeof(type_instance), "%s-%s", r->interface, name); + ssnprintf(type_instance, sizeof(type_instance), "%s-%s", r->interface, name); cr_submit_io(rd, "if_octets", type_instance, (derive_t)r->rx_bytes, (derive_t)r->tx_bytes); cr_submit_gauge(rd, "snr", type_instance, (gauge_t)r->signal_to_noise); @@ -438,7 +438,7 @@ static int cr_config_router(oconfig_item_t *ci) /* {{{ */ return status; } - snprintf(read_name, sizeof(read_name), "routeros/%s", router_data->node); + ssnprintf(read_name, sizeof(read_name), "routeros/%s", router_data->node); return plugin_register_complex_read( /* group = */ NULL, read_name, cr_read, /* interval = */ 0, &(user_data_t){ diff --git a/src/rrdcached.c b/src/rrdcached.c index 9aeb71a5..4623d785 100644 --- a/src/rrdcached.c +++ b/src/rrdcached.c @@ -67,7 +67,7 @@ static int value_list_to_string(char *buffer, int buffer_len, memset(buffer, '\0', buffer_len); int status = - snprintf(buffer, buffer_len, "%.6f", CDTIME_T_TO_DOUBLE(vl->time)); + ssnprintf(buffer, buffer_len, "%.6f", CDTIME_T_TO_DOUBLE(vl->time)); if ((status < 1) || (status >= buffer_len)) return -1; int offset = status; @@ -80,16 +80,16 @@ 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, ":%" PRIu64, + status = ssnprintf(buffer + offset, buffer_len - offset, ":%" PRIu64, (uint64_t)vl->values[i].counter); } else if (ds->ds[i].type == DS_TYPE_GAUGE) { - status = snprintf(buffer + offset, buffer_len - offset, ":%f", + status = ssnprintf(buffer + offset, buffer_len - offset, ":%f", vl->values[i].gauge); } else if (ds->ds[i].type == DS_TYPE_DERIVE) { - status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIi64, + status = ssnprintf(buffer + offset, buffer_len - offset, ":%" PRIi64, vl->values[i].derive); } else /* if (ds->ds[i].type == DS_TYPE_ABSOLUTE) */ { - status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIu64, + status = ssnprintf(buffer + offset, buffer_len - offset, ":%" PRIu64, vl->values[i].absolute); } @@ -461,9 +461,9 @@ static int rc_flush(__attribute__((unused)) cdtime_t timeout, /* {{{ */ char filename[PATH_MAX + 1]; if (datadir != NULL) - snprintf(filename, sizeof(filename), "%s/%s.rrd", datadir, identifier); + ssnprintf(filename, sizeof(filename), "%s/%s.rrd", datadir, identifier); else - snprintf(filename, sizeof(filename), "%s.rrd", identifier); + ssnprintf(filename, sizeof(filename), "%s.rrd", identifier); rrd_clear_error(); int status = rrdc_connect(daemon_address); diff --git a/src/rrdtool.c b/src/rrdtool.c index d0849d12..fc659925 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -173,7 +173,7 @@ static int value_list_to_string_multiple(char *buffer, int buffer_len, memset(buffer, '\0', buffer_len); tt = CDTIME_T_TO_TIME_T(vl->time); - status = snprintf(buffer, buffer_len, "%u", (unsigned int)tt); + status = ssnprintf(buffer, buffer_len, "%u", (unsigned int)tt); if ((status < 1) || (status >= buffer_len)) return -1; offset = status; @@ -186,16 +186,16 @@ static int value_list_to_string_multiple(char *buffer, int buffer_len, return -1; if (ds->ds[i].type == DS_TYPE_COUNTER) - status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIu64, + status = ssnprintf(buffer + offset, buffer_len - offset, ":%" PRIu64, (uint64_t)vl->values[i].counter); else if (ds->ds[i].type == DS_TYPE_GAUGE) - status = snprintf(buffer + offset, buffer_len - offset, ":" GAUGE_FORMAT, + status = ssnprintf(buffer + offset, buffer_len - offset, ":" GAUGE_FORMAT, vl->values[i].gauge); else if (ds->ds[i].type == DS_TYPE_DERIVE) - status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIi64, + status = ssnprintf(buffer + offset, buffer_len - offset, ":%" PRIi64, vl->values[i].derive); else /*if (ds->ds[i].type == DS_TYPE_ABSOLUTE) */ - status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIu64, + status = ssnprintf(buffer + offset, buffer_len - offset, ":%" PRIu64, vl->values[i].absolute); if ((status < 1) || (status >= (buffer_len - offset))) @@ -218,19 +218,19 @@ static int value_list_to_string(char *buffer, int buffer_len, tt = CDTIME_T_TO_TIME_T(vl->time); switch (ds->ds[0].type) { case DS_TYPE_DERIVE: - status = snprintf(buffer, buffer_len, "%u:%" PRIi64, (unsigned)tt, + status = ssnprintf(buffer, buffer_len, "%u:%" PRIi64, (unsigned)tt, vl->values[0].derive); break; case DS_TYPE_GAUGE: - status = snprintf(buffer, buffer_len, "%u:" GAUGE_FORMAT, (unsigned)tt, + status = ssnprintf(buffer, buffer_len, "%u:" GAUGE_FORMAT, (unsigned)tt, vl->values[0].gauge); break; case DS_TYPE_COUNTER: - status = snprintf(buffer, buffer_len, "%u:%" PRIu64, (unsigned)tt, + status = ssnprintf(buffer, buffer_len, "%u:%" PRIu64, (unsigned)tt, (uint64_t)vl->values[0].counter); break; case DS_TYPE_ABSOLUTE: - status = snprintf(buffer, buffer_len, "%u:%" PRIu64, (unsigned)tt, + status = ssnprintf(buffer, buffer_len, "%u:%" PRIu64, (unsigned)tt, vl->values[0].absolute); break; default: @@ -566,9 +566,9 @@ static int rrd_cache_flush_identifier(cdtime_t timeout, now = cdtime(); if (datadir == NULL) - snprintf(key, sizeof(key), "%s.rrd", identifier); + ssnprintf(key, sizeof(key), "%s.rrd", identifier); else - snprintf(key, sizeof(key), "%s/%s.rrd", datadir, identifier); + ssnprintf(key, sizeof(key), "%s/%s.rrd", datadir, identifier); key[sizeof(key) - 1] = '\0'; status = c_avl_get(cache, key, (void *)&rc); diff --git a/src/sigrok.c b/src/sigrok.c index a8b67afe..78d1f1db 100644 --- a/src/sigrok.c +++ b/src/sigrok.c @@ -247,7 +247,7 @@ static int sigrok_init_driver(struct config_device *cfdev, } cfdev->sdi = devlist->data; g_slist_free(devlist); - snprintf(hwident, sizeof(hwident), "%s %s %s", + ssnprintf(hwident, sizeof(hwident), "%s %s %s", cfdev->sdi->vendor ? cfdev->sdi->vendor : "", cfdev->sdi->model ? cfdev->sdi->model : "", cfdev->sdi->version ? cfdev->sdi->version : ""); diff --git a/src/smart.c b/src/smart.c index 2dfb924f..85ebf0af 100644 --- a/src/smart.c +++ b/src/smart.c @@ -116,7 +116,7 @@ static void handle_attribute(SkDisk *d, const SkSmartAttributeParsedData *a, sstrncpy(notif.host, hostname_g, sizeof(notif.host)); sstrncpy(notif.plugin_instance, name, sizeof(notif.plugin_instance)); sstrncpy(notif.type_instance, a->name, sizeof(notif.type_instance)); - snprintf(notif.message, sizeof(notif.message), + ssnprintf(notif.message, sizeof(notif.message), "attribute %s is below allowed threshold (%d < %d)", a->name, a->current_value, a->threshold); plugin_dispatch_notification(¬if); diff --git a/src/snmp.c b/src/snmp.c index c921e028..e0ca7ff6 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -171,7 +171,7 @@ static int csnmp_oid_to_string(char *buffer, size_t buffer_size, char *oid_str_ptr[MAX_OID_LEN]; for (size_t i = 0; i < o->oid_len; i++) { - snprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]); + ssnprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]); oid_str_ptr[i] = oid_str[i]; } @@ -871,7 +871,7 @@ static int csnmp_config_add_host(oconfig_item_t *ci) { "= %i }", hd->name, hd->address, hd->community, hd->version); - snprintf(cb_name, sizeof(cb_name), "snmp-%s", hd->name); + ssnprintf(cb_name, sizeof(cb_name), "snmp-%s", hd->name); status = plugin_register_complex_read( /* group = */ NULL, cb_name, csnmp_read_host, interval, @@ -1140,7 +1140,7 @@ static int csnmp_strvbcopy_hexstring(char *dst, /* {{{ */ for (size_t i = 0; i < vb->val_len; i++) { int status; - status = snprintf(buffer_ptr, buffer_free, (i == 0) ? "%02x" : ":%02x", + status = ssnprintf(buffer_ptr, buffer_free, (i == 0) ? "%02x" : ":%02x", (unsigned int)vb->val.bitstring[i]); assert(status >= 0); @@ -1173,7 +1173,7 @@ static int csnmp_strvbcopy(char *dst, /* {{{ */ else if (vb->type == ASN_BIT_STR) src = (char *)vb->val.bitstring; else if (vb->type == ASN_IPADDRESS) { - return snprintf(dst, dst_size, + return ssnprintf(dst, dst_size, "%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 "", (uint8_t)vb->val.string[0], (uint8_t)vb->val.string[1], (uint8_t)vb->val.string[2], (uint8_t)vb->val.string[3]); @@ -1234,7 +1234,7 @@ static csnmp_cell_char_t *csnmp_get_char_cell(const struct variable_list *vb, value_t val = csnmp_value_list_to_value( vb, DS_TYPE_COUNTER, /* scale = */ 1.0, /* shift = */ 0.0, hd->name, dd->name); - snprintf(il->value, sizeof(il->value), "%" PRIu64, (uint64_t)val.counter); + ssnprintf(il->value, sizeof(il->value), "%" PRIu64, (uint64_t)val.counter); } return il; @@ -1479,7 +1479,7 @@ static int csnmp_dispatch_table(host_definition_t *host, if (data->host.prefix == NULL) sstrncpy(vl.host, temp, sizeof(vl.host)); else - snprintf(vl.host, sizeof(vl.host), "%s%s", data->host.prefix, temp); + ssnprintf(vl.host, sizeof(vl.host), "%s%s", data->host.prefix, temp); } else { sstrncpy(vl.host, host->name, sizeof(vl.host)); } @@ -1495,7 +1495,7 @@ static int csnmp_dispatch_table(host_definition_t *host, if (data->type_instance.prefix == NULL) 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->type_instance.prefix, temp); } else if (data->type_instance.value) { sstrncpy(vl.type_instance, data->type_instance.value, @@ -1513,7 +1513,7 @@ static int csnmp_dispatch_table(host_definition_t *host, if (data->plugin_instance.prefix == NULL) sstrncpy(vl.plugin_instance, temp, sizeof(vl.plugin_instance)); else - snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s%s", + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s%s", data->plugin_instance.prefix, temp); } else if (data->plugin_instance.value) { sstrncpy(vl.plugin_instance, data->plugin_instance.value, diff --git a/src/snmp_agent.c b/src/snmp_agent.c index cbd33664..97eae7c0 100644 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@ -172,7 +172,7 @@ static int snmp_agent_oid_to_string(char *buf, size_t buf_size, char *oid_str_ptr[MAX_OID_LEN]; for (size_t i = 0; i < o->oid_len; i++) { - snprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]); + ssnprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]); oid_str_ptr[i] = oid_str[i]; } @@ -736,12 +736,12 @@ static void snmp_agent_table_data_remove(data_definition_t *dd, if (index == NULL) snmp_agent_oid_to_string(index_str, sizeof(index_str), index_oid); else - snprintf(index_str, sizeof(index_str), "%d", *index); + ssnprintf(index_str, sizeof(index_str), "%d", *index); notification_t n = { .severity = NOTIF_WARNING, .time = cdtime(), .plugin = PLUGIN_NAME}; sstrncpy(n.host, hostname_g, sizeof(n.host)); - snprintf(n.message, sizeof(n.message), + ssnprintf(n.message, sizeof(n.message), "Removed data row from table %s with index %s", td->name, index_str); DEBUG(PLUGIN_NAME ": %s", n.message); plugin_dispatch_notification(&n); @@ -960,7 +960,7 @@ static int snmp_agent_build_name(char **name, c_avl_tree_t *tokens) { strncat(out, tok->str, DATA_MAX_NAME_LEN - strlen(out) - 1); if (tok->key != NULL) { if (tok->key->type == ASN_INTEGER) { - snprintf(str, sizeof(str), "%ld", *tok->key->val.integer); + ssnprintf(str, sizeof(str), "%ld", *tok->key->val.integer); strncat(out, str, DATA_MAX_NAME_LEN - strlen(out) - 1); } else /* OCTET_STR */ strncat(out, (char *)tok->key->val.string, @@ -1013,7 +1013,7 @@ static int snmp_agent_format_name(char *name, int name_len, } if (td->index_keys[i].type == ASN_INTEGER) { - snprintf(str, sizeof(str), "%ld", *key->val.integer); + ssnprintf(str, sizeof(str), "%ld", *key->val.integer); fields[source] = str; } else /* OCTET_STR */ fields[source] = (char *)key->val.string; @@ -1836,7 +1836,7 @@ static int snmp_agent_set_vardata(void *data, size_t *data_len, u_char asn_type, case ASN_OCTET_STR: if (type == DS_TYPE_GAUGE) { char buf[DATA_MAX_NAME_LEN]; - snprintf(buf, sizeof(buf), "%.2f", val->gauge); + ssnprintf(buf, sizeof(buf), "%.2f", val->gauge); if (*data_len < strlen(buf)) return -EINVAL; *data_len = strlen(buf); @@ -1995,12 +1995,12 @@ static int snmp_agent_update_index(data_definition_t *dd, if (index == NULL) snmp_agent_oid_to_string(index_str, sizeof(index_str), index_oid); else - snprintf(index_str, sizeof(index_str), "%d", *index); + ssnprintf(index_str, sizeof(index_str), "%d", *index); notification_t n = { .severity = NOTIF_OKAY, .time = cdtime(), .plugin = PLUGIN_NAME}; sstrncpy(n.host, hostname_g, sizeof(n.host)); - snprintf(n.message, sizeof(n.message), + ssnprintf(n.message, sizeof(n.message), "Data added to table %s with index %s", td->name, index_str); DEBUG(PLUGIN_NAME ": %s", n.message); diff --git a/src/threshold.c b/src/threshold.c index a3d865ba..93ca5fdb 100644 --- a/src/threshold.c +++ b/src/threshold.c @@ -335,22 +335,22 @@ static int ut_report_state(const data_set_t *ds, const value_list_t *vl, n.time = vl->time; - status = snprintf(buf, bufsize, "Host %s, plugin %s", vl->host, vl->plugin); + 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)", vl->plugin_instance); + 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)", vl->type_instance); + status = ssnprintf(buf, bufsize, " (instance %s)", vl->type_instance); buf += status; bufsize -= status; } @@ -365,9 +365,9 @@ static int ut_report_state(const data_set_t *ds, const value_list_t *vl, /* Send an okay notification */ if (state == STATE_OKAY) { if (state_old == STATE_MISSING) - snprintf(buf, bufsize, ": Value is no longer missing."); + ssnprintf(buf, bufsize, ": Value is no longer missing."); else - snprintf(buf, bufsize, ": All data sources are within range again. " + ssnprintf(buf, bufsize, ": All data sources are within range again. " "Current value of \"%s\" is %f.", ds->ds[ds_index].name, values[ds_index]); } else if (state == STATE_UNKNOWN) { @@ -383,7 +383,7 @@ static int ut_report_state(const data_set_t *ds, const value_list_t *vl, if (th->flags & UT_FLAG_INVERT) { if (!isnan(min) && !isnan(max)) { - snprintf(buf, bufsize, + ssnprintf(buf, bufsize, ": Data source \"%s\" is currently " "%f. That is within the %s region of %f%s and %f%s.", ds->ds[ds_index].name, values[ds_index], @@ -391,7 +391,7 @@ static int ut_report_state(const data_set_t *ds, const value_list_t *vl, ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "", max, ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : ""); } else { - snprintf(buf, bufsize, ": Data source \"%s\" is currently " + ssnprintf(buf, bufsize, ": Data source \"%s\" is currently " "%f. That is %s the %s threshold of %f%s.", ds->ds[ds_index].name, values[ds_index], isnan(min) ? "below" : "above", @@ -416,7 +416,7 @@ static int ut_report_state(const data_set_t *ds, const value_list_t *vl, else value = 100.0 * values[ds_index] / sum; - snprintf(buf, bufsize, + ssnprintf(buf, bufsize, ": Data source \"%s\" is currently " "%g (%.2f%%). That is %s the %s threshold of %.2f%%.", ds->ds[ds_index].name, values[ds_index], value, @@ -425,7 +425,7 @@ static int ut_report_state(const data_set_t *ds, const value_list_t *vl, (value < min) ? min : max); } else /* is not inverted */ { - snprintf(buf, bufsize, ": Data source \"%s\" is currently " + 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", @@ -689,7 +689,7 @@ static int ut_missing(const value_list_t *vl, FORMAT_VL(identifier, sizeof(identifier), vl); NOTIFICATION_INIT_VL(&n, vl); - snprintf(n.message, sizeof(n.message), + ssnprintf(n.message, sizeof(n.message), "%s has not been updated for %.3f seconds.", identifier, CDTIME_T_TO_DOUBLE(missing_time)); n.time = now; diff --git a/src/utils/cmds/cmds_test.c b/src/utils/cmds/cmds_test.c index 713f0324..80fbd2fa 100644 --- a/src/utils/cmds/cmds_test.c +++ b/src/utils/cmds/cmds_test.c @@ -196,7 +196,7 @@ DEF_TEST(parse) { memset(&cmd, 0, sizeof(cmd)); status = cmd_parse(input, &cmd, parse_data[i].opts, &err); - snprintf(description, sizeof(description), "cmd_parse (\"%s\", opts=%p) = " + ssnprintf(description, sizeof(description), "cmd_parse (\"%s\", opts=%p) = " "%d (type=%d [%s]); want %d " "(type=%d [%s])", parse_data[i].input, parse_data[i].opts, status, cmd.type, diff --git a/src/utils/common/common.c b/src/utils/common/common.c index d15f9b7c..e986da81 100644 --- a/src/utils/common/common.c +++ b/src/utils/common/common.c @@ -89,6 +89,22 @@ char *sstrncpy(char *dest, const char *src, size_t n) { return dest; } /* char *sstrncpy */ +/* ssnprintf returns zero on success, one if truncation occurred + and a negative integer onerror. */ +int ssnprintf(char *str, size_t sz, const char *format, ...) { + va_list ap; + va_start(ap, format); + + int ret = vsnprintf(str, sz, format, ap); + + va_end(ap); + + if (ret < 0) { + return ret; + } + return (size_t)ret >= sz; +} /* int ssnprintf */ + char *ssnprintf_alloc(char const *format, ...) /* {{{ */ { char static_buffer[1024] = ""; diff --git a/src/utils/common/common.h b/src/utils/common/common.h index addf06d3..480d0e90 100644 --- a/src/utils/common/common.h +++ b/src/utils/common/common.h @@ -66,6 +66,9 @@ typedef struct value_to_rate_state_s value_to_rate_state_t; char *sstrncpy(char *dest, const char *src, size_t n); +__attribute__((format(printf, 3, 4))) int ssnprintf(char *str, size_t size, + char const *format, ...); + __attribute__((format(printf, 1, 2))) char *ssnprintf_alloc(char const *format, ...); diff --git a/src/utils/config_cores/config_cores.c b/src/utils/config_cores/config_cores.c index 13ea6878..b6dedbc9 100644 --- a/src/utils/config_cores/config_cores.c +++ b/src/utils/config_cores/config_cores.c @@ -254,7 +254,7 @@ int config_cores_parse(const oconfig_item_t *ci, core_groups_list_t *cgl) { } else { for (size_t j = 0; j < n && cg_idx < STATIC_ARRAY_SIZE(cgroups); j++) { char desc[DATA_MAX_NAME_LEN]; - snprintf(desc, sizeof(desc), "%u", cores[j]); + ssnprintf(desc, sizeof(desc), "%u", cores[j]); cgroups[cg_idx].desc = strdup(desc); if (cgroups[cg_idx].desc == NULL) { @@ -313,7 +313,7 @@ int config_cores_default(int num_cores, core_groups_list_t *cgl) { for (int i = 0; i < num_cores; i++) { char desc[DATA_MAX_NAME_LEN]; - snprintf(desc, sizeof(desc), "%d", i); + ssnprintf(desc, sizeof(desc), "%d", i); cgl->cgroups[i].cores = calloc(1, sizeof(*(cgl->cgroups[i].cores))); if (cgl->cgroups[i].cores == NULL) { diff --git a/src/utils/db_query/db_query.c b/src/utils/db_query/db_query.c index 392bd56f..2c5eab3f 100644 --- a/src/utils/db_query/db_query.c +++ b/src/utils/db_query/db_query.c @@ -228,7 +228,7 @@ static int udb_result_submit(udb_result_t *r, /* {{{ */ } tmp[sizeof(tmp) - 1] = '\0'; - snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s", + ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s", r->instance_prefix, tmp); } } diff --git a/src/utils/dns/dns.c b/src/utils/dns/dns.c index 2ea919b7..020e9fe8 100644 --- a/src/utils/dns/dns.c +++ b/src/utils/dns/dns.c @@ -912,7 +912,7 @@ const char *qtype_str(int t) { return "ANY"; /* ... 255 */ #endif /* __BIND >= 19950621 */ default: - snprintf(buf, sizeof(buf), "#%i", t); + ssnprintf(buf, sizeof(buf), "#%i", t); return buf; } /* switch (t) */ } @@ -931,7 +931,7 @@ const char *opcode_str(int o) { case 5: return "Update"; default: - snprintf(buf, sizeof(buf), "Opcode%d", o); + ssnprintf(buf, sizeof(buf), "Opcode%d", o); return buf; } } @@ -998,7 +998,7 @@ const char *rcode_str(int rcode) { #endif /* RFC2136 rcodes */ #endif /* __BIND >= 19950621 */ default: - snprintf(buf, sizeof(buf), "RCode%i", rcode); + ssnprintf(buf, sizeof(buf), "RCode%i", rcode); return buf; } } /* const char *rcode_str (int rcode) */ diff --git a/src/utils/dpdk/dpdk.c b/src/utils/dpdk/dpdk.c index 5e38ab36..4d05424b 100644 --- a/src/utils/dpdk/dpdk.c +++ b/src/utils/dpdk/dpdk.c @@ -110,9 +110,9 @@ static void dpdk_helper_config_default(dpdk_helper_ctx_t *phc) { DPDK_HELPER_TRACE(phc->shm_name); - snprintf(phc->eal_config.coremask, DATA_MAX_NAME_LEN, "%s", "0xf"); - snprintf(phc->eal_config.memory_channels, DATA_MAX_NAME_LEN, "%s", "1"); - snprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, "%s", + ssnprintf(phc->eal_config.coremask, DATA_MAX_NAME_LEN, "%s", "0xf"); + ssnprintf(phc->eal_config.memory_channels, DATA_MAX_NAME_LEN, "%s", "1"); + ssnprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, "%s", DPDK_DEFAULT_RTE_CONFIG); } @@ -189,10 +189,10 @@ int dpdk_helper_eal_config_parse(dpdk_helper_ctx_t *phc, oconfig_item_t *ci) { status = cf_util_get_string_buffer(child, prefix, sizeof(prefix)); if (status == 0) { #if RTE_VERSION <= RTE_VERSION_NUM(18, 5, 0, 0) - snprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, + ssnprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, "/var/run/.%s_config", prefix); #else - snprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, + ssnprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, "/var/run/dpdk/%s/config", prefix); #endif DEBUG("dpdk_common: EAL:File prefix %s", phc->eal_config.file_prefix); diff --git a/src/utils/format_graphite/format_graphite_test.c b/src/utils/format_graphite/format_graphite_test.c index 2c14d010..e01317b2 100644 --- a/src/utils/format_graphite/format_graphite_test.c +++ b/src/utils/format_graphite/format_graphite_test.c @@ -154,7 +154,7 @@ DEF_TEST(metric_name) { }; char want[1024]; - snprintf(want, sizeof(want), "%s 42 1480063672\r\n", cases[i].want_name); + ssnprintf(want, sizeof(want), "%s 42 1480063672\r\n", cases[i].want_name); if (cases[i].plugin_instance != NULL) sstrncpy(vl.plugin_instance, cases[i].plugin_instance, diff --git a/src/utils/format_stackdriver/format_stackdriver.c b/src/utils/format_stackdriver/format_stackdriver.c index 80b85ae4..9b8b5474 100644 --- a/src/utils/format_stackdriver/format_stackdriver.c +++ b/src/utils/format_stackdriver/format_stackdriver.c @@ -144,16 +144,16 @@ static int format_typed_value(yajl_gen gen, int ds_type, value_t v, } case DS_TYPE_DERIVE: { derive_t diff = v.derive - (derive_t)start_value; - snprintf(integer, sizeof(integer), "%" PRIi64, diff); + ssnprintf(integer, sizeof(integer), "%" PRIi64, diff); break; } case DS_TYPE_COUNTER: { counter_t diff = counter_diff((counter_t)start_value, v.counter); - snprintf(integer, sizeof(integer), "%llu", diff); + ssnprintf(integer, sizeof(integer), "%llu", diff); break; } case DS_TYPE_ABSOLUTE: { - snprintf(integer, sizeof(integer), "%" PRIu64, v.absolute); + ssnprintf(integer, sizeof(integer), "%" PRIu64, v.absolute); break; } default: { @@ -210,10 +210,10 @@ static int metric_type(char *buffer, size_t buffer_size, data_set_t const *ds, #define GCM_PREFIX "custom.googleapis.com/collectd/" if ((ds_index != 0) || strcmp("value", ds_name) != 0) { - snprintf(buffer, buffer_size, GCM_PREFIX "%s/%s_%s", vl->plugin, vl->type, + ssnprintf(buffer, buffer_size, GCM_PREFIX "%s/%s_%s", vl->plugin, vl->type, ds_name); } else { - snprintf(buffer, buffer_size, GCM_PREFIX "%s/%s", vl->plugin, vl->type); + ssnprintf(buffer, buffer_size, GCM_PREFIX "%s/%s", vl->plugin, vl->type); } char const *whitelist = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -280,7 +280,7 @@ static int read_cumulative_state(data_set_t const *ds, value_list_t const *vl, } char start_value_key[DATA_MAX_NAME_LEN]; - snprintf(start_value_key, sizeof(start_value_key), + ssnprintf(start_value_key, sizeof(start_value_key), "stackdriver:start_value[%d]", ds_index); int status = diff --git a/src/utils/gce/gce.c b/src/utils/gce/gce.c index 80927656..0c97d909 100644 --- a/src/utils/gce/gce.c +++ b/src/utils/gce/gce.c @@ -227,7 +227,7 @@ char *gce_scope(char const *email) /* {{{ */ { char url[1024]; - snprintf(url, sizeof(url), GCE_SCOPE_URL_FORMAT, + ssnprintf(url, sizeof(url), GCE_SCOPE_URL_FORMAT, (email != NULL) ? email : GCE_DEFAULT_SERVICE_ACCOUNT); return read_url(url); @@ -252,7 +252,7 @@ int gce_access_token(char const *email, char *buffer, return 0; } - snprintf(url, sizeof(url), GCE_TOKEN_URL_FORMAT, email); + ssnprintf(url, sizeof(url), GCE_TOKEN_URL_FORMAT, email); json = read_url(url); if (json == NULL) { pthread_mutex_unlock(&token_lock); diff --git a/src/utils/oauth/oauth.c b/src/utils/oauth/oauth.c index 4b31056d..b7b1978e 100644 --- a/src/utils/oauth/oauth.c +++ b/src/utils/oauth/oauth.c @@ -184,7 +184,7 @@ static int get_claim(oauth_t *auth, char *buffer, size_t buffer_size) /* {{{ */ /* create the claim set */ status = - snprintf(claim, sizeof(claim), OAUTH_CLAIM_FORMAT, auth->iss, auth->scope, + ssnprintf(claim, sizeof(claim), OAUTH_CLAIM_FORMAT, auth->iss, auth->scope, auth->aud, (unsigned long)CDTIME_T_TO_TIME_T(exp), (unsigned long)CDTIME_T_TO_TIME_T(iat)); if (status < 1) @@ -209,7 +209,7 @@ static int get_signature(char *buffer, size_t buffer_size, /* {{{ */ int status; /* Make the string to sign */ - payload_len = snprintf(payload, sizeof(payload), "%s.%s", header, claim); + payload_len = ssnprintf(payload, sizeof(payload), "%s.%s", header, claim); if (payload_len < 1) { return -1; } else if (payload_len >= sizeof(payload)) { @@ -277,7 +277,7 @@ static int get_assertion(oauth_t *auth, char *buffer, if (status != 0) return -1; - status = snprintf(buffer, buffer_size, "%s.%s.%s", header, claim, signature); + status = ssnprintf(buffer, buffer_size, "%s.%s.%s", header, claim, signature); if (status < 1) return -1; else if ((size_t)status >= buffer_size) @@ -350,7 +350,7 @@ static int new_token(oauth_t *auth) /* {{{ */ return -1; } - snprintf(post_data, sizeof(post_data), "grant_type=%s&assertion=%s", + ssnprintf(post_data, sizeof(post_data), "grant_type=%s&assertion=%s", OAUTH_GRANT_TYPE, assertion); curl = curl_easy_init(); @@ -589,7 +589,7 @@ oauth_google_t oauth_create_google_default(char const *scope) { char const *home; if ((home = getenv("HOME")) != NULL) { char path[PATH_MAX]; - snprintf(path, sizeof(path), + ssnprintf(path, sizeof(path), "%s/.config/gcloud/application_default_credentials.json", home); oauth_google_t ret = oauth_create_google_file(path, scope); diff --git a/src/utils/ovs/ovs.c b/src/utils/ovs/ovs.c index 46c2c269..127a9178 100644 --- a/src/utils/ovs/ovs.c +++ b/src/utils/ovs/ovs.c @@ -1117,7 +1117,7 @@ int ovs_db_send_request(ovs_db_t *pdb, const char *method, const char *params, /* generate id field */ OVS_YAJL_CALL(ovs_yajl_gen_tstring, jgen, "id"); uid = ovs_uid_generate(); - snprintf(uid_buff, sizeof(uid_buff), "%" PRIX64, uid); + ssnprintf(uid_buff, sizeof(uid_buff), "%" PRIX64, uid); OVS_YAJL_CALL(ovs_yajl_gen_tstring, jgen, uid_buff); OVS_YAJL_CALL(yajl_gen_map_close, jgen); @@ -1203,7 +1203,7 @@ int ovs_db_table_cb_register(ovs_db_t *pdb, const char *tb_name, OVS_YAJL_CALL(ovs_yajl_gen_tstring, jgen, OVS_DB_DEFAULT_DB_NAME); /* uid string */ - snprintf(uid_str, sizeof(uid_str), "%" PRIX64, new_cb->uid); + ssnprintf(uid_str, sizeof(uid_str), "%" PRIX64, new_cb->uid); OVS_YAJL_CALL(ovs_yajl_gen_tstring, jgen, uid_str); /* */ diff --git a/src/utils/rrdcreate/rrdcreate.c b/src/utils/rrdcreate/rrdcreate.c index ef012343..6a2e09a2 100644 --- a/src/utils/rrdcreate/rrdcreate.c +++ b/src/utils/rrdcreate/rrdcreate.c @@ -208,7 +208,7 @@ static int rra_get(char ***ret, const value_list_t *vl, /* {{{ */ if (rra_num >= rra_max) break; - status = snprintf(buffer, sizeof(buffer), "RRA:%s:%.10f:%u:%u", + status = ssnprintf(buffer, sizeof(buffer), "RRA:%s:%.10f:%u:%u", rra_types[j], cfg->xff, cdp_len, cdp_num); if ((status < 0) || ((size_t)status >= sizeof(buffer))) { @@ -278,14 +278,14 @@ static int ds_get(char ***ret, /* {{{ */ if (isnan(d->min)) { sstrncpy(min, "U", sizeof(min)); } else - snprintf(min, sizeof(min), "%f", d->min); + ssnprintf(min, sizeof(min), "%f", d->min); if (isnan(d->max)) { sstrncpy(max, "U", sizeof(max)); } else - snprintf(max, sizeof(max), "%f", d->max); + ssnprintf(max, sizeof(max), "%f", d->max); - status = snprintf( + status = ssnprintf( buffer, sizeof(buffer), "DS:%s:%s:%i:%s:%s", d->name, type, (cfg->heartbeat > 0) ? cfg->heartbeat : (int)CDTIME_T_TO_TIME_T(2 * vl->interval), @@ -367,8 +367,8 @@ static int srrd_create(const char *filename, /* {{{ */ if (last_up == 0) last_up = time(NULL) - 10; - snprintf(pdp_step_str, sizeof(pdp_step_str), "%lu", pdp_step); - snprintf(last_up_str, sizeof(last_up_str), "%lu", (unsigned long)last_up); + ssnprintf(pdp_step_str, sizeof(pdp_step_str), "%lu", pdp_step); + ssnprintf(last_up_str, sizeof(last_up_str), "%lu", (unsigned long)last_up); new_argv[0] = "create"; new_argv[1] = (void *)filename; @@ -496,7 +496,7 @@ static void *srrd_create_thread(void *targs) /* {{{ */ return 0; } - snprintf(tmpfile, sizeof(tmpfile), "%s.async", args->filename); + ssnprintf(tmpfile, sizeof(tmpfile), "%s.async", args->filename); status = srrd_create(tmpfile, args->pdp_step, args->last_up, args->argc, (void *)args->argv); diff --git a/src/varnish.c b/src/varnish.c index b4ae4385..339343a3 100644 --- a/src/varnish.c +++ b/src/varnish.c @@ -107,7 +107,7 @@ static int varnish_submit(const char *plugin_instance, /* {{{ */ if (plugin_instance == NULL) plugin_instance = "default"; - snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s", + ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s", plugin_instance, category); sstrncpy(vl.type, type, sizeof(vl.type)); @@ -1759,7 +1759,7 @@ static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */ return EINVAL; } - snprintf(callback_name, sizeof(callback_name), "varnish/%s", + ssnprintf(callback_name, sizeof(callback_name), "varnish/%s", (conf->instance == NULL) ? "localhost" : conf->instance); plugin_register_complex_read( diff --git a/src/virt.c b/src/virt.c index 5e7ae28c..d3d8c6a7 100644 --- a/src/virt.c +++ b/src/virt.c @@ -1004,7 +1004,7 @@ static void vcpu_submit(derive_t value, virDomainPtr dom, int vcpu_nr, const char *type) { char type_instance[DATA_MAX_NAME_LEN]; - snprintf(type_instance, sizeof(type_instance), "%d", vcpu_nr); + ssnprintf(type_instance, sizeof(type_instance), "%d", vcpu_nr); submit(dom, type, type_instance, &(value_t){.derive = value}, 1); } @@ -1026,7 +1026,7 @@ static void disk_block_stats_submit(struct lv_block_stats *bstats, } char flush_type_instance[DATA_MAX_NAME_LEN]; - snprintf(flush_type_instance, sizeof(flush_type_instance), "flush-%s", + ssnprintf(flush_type_instance, sizeof(flush_type_instance), "flush-%s", type_instance); if ((bstats->bi.rd_req != -1) && (bstats->bi.wr_req != -1)) @@ -1130,7 +1130,7 @@ static void domain_state_submit_notif(virDomainPtr dom, int state, int reason) { const char *reason_str = "N/A"; #endif - snprintf(msg, sizeof(msg), "Domain state: %s. Reason: %s", state_str, + ssnprintf(msg, sizeof(msg), "Domain state: %s. Reason: %s", state_str, reason_str); int severity; @@ -1578,7 +1578,7 @@ static void vcpu_pin_submit(virDomainPtr dom, int max_cpus, int vcpu, char type_instance[DATA_MAX_NAME_LEN]; bool is_set = VIR_CPU_USABLE(cpu_maps, cpu_map_len, vcpu, cpu); - snprintf(type_instance, sizeof(type_instance), "vcpu_%d-cpu_%d", vcpu, cpu); + ssnprintf(type_instance, sizeof(type_instance), "vcpu_%d-cpu_%d", vcpu, cpu); submit(dom, "cpu_affinity", type_instance, &(value_t){.gauge = is_set}, 1); } } @@ -2402,7 +2402,7 @@ static int lv_init_instance(size_t i, plugin_read_cb callback) { memset(lv_ud, 0, sizeof(*lv_ud)); - snprintf(inst->tag, sizeof(inst->tag), "%s-%" PRIsz, PLUGIN_NAME, i); + ssnprintf(inst->tag, sizeof(inst->tag), "%s-%" PRIsz, PLUGIN_NAME, i); inst->id = i; user_data_t *ud = &(lv_ud->ud); @@ -2472,7 +2472,7 @@ static int lv_domain_get_tag(xmlXPathContextPtr xpath_ctx, const char *dom_name, goto done; } - snprintf(xpath_str, sizeof(xpath_str), "/domain/metadata/%s:%s/text()", + ssnprintf(xpath_str, sizeof(xpath_str), "/domain/metadata/%s:%s/text()", METADATA_VM_PARTITION_PREFIX, METADATA_VM_PARTITION_ELEMENT); xpath_obj = xmlXPathEvalExpression((xmlChar *)xpath_str, xpath_ctx); if (xpath_obj == NULL) { @@ -2675,7 +2675,7 @@ static void lv_add_network_interfaces(struct lv_read_state *state, break; case if_number: { char number_string[4]; - snprintf(number_string, sizeof(number_string), "%d", itf_number); + ssnprintf(number_string, sizeof(number_string), "%d", itf_number); if (ignore_device_match(il_interface_devices, domname, number_string) != 0) device_ignored = true; @@ -2976,7 +2976,7 @@ static int add_interface_device(struct lv_read_state *state, virDomainPtr dom, } char number_string[21]; - snprintf(number_string, sizeof(number_string), "interface-%u", number); + ssnprintf(number_string, sizeof(number_string), "interface-%u", number); char *number_copy = strdup(number_string); if (!number_copy) { sfree(path_copy); @@ -3015,7 +3015,7 @@ static int ignore_device_match(ignorelist_t *il, const char *domname, ERROR(PLUGIN_NAME " plugin: malloc failed."); return 0; } - snprintf(name, n, "%s:%s", domname, devpath); + ssnprintf(name, n, "%s:%s", domname, devpath); int r = ignorelist_match(il, name); sfree(name); return r; diff --git a/src/write_kafka.c b/src/write_kafka.c index 4c7a4715..4decc4e4 100644 --- a/src/write_kafka.c +++ b/src/write_kafka.c @@ -97,7 +97,7 @@ static uint32_t kafka_hash(const char *keydata, size_t keylen) { #define KAFKA_RANDOM_KEY_BUFFER \ (char[KAFKA_RANDOM_KEY_SIZE]) { "" } static char *kafka_random_key(char buffer[static KAFKA_RANDOM_KEY_SIZE]) { - snprintf(buffer, KAFKA_RANDOM_KEY_SIZE, "%08" PRIX32, cdrand_u()); + ssnprintf(buffer, KAFKA_RANDOM_KEY_SIZE, "%08" PRIX32, cdrand_u()); return buffer; } @@ -410,7 +410,7 @@ static void kafka_config_topic(rd_kafka_conf_t *conf, rd_kafka_topic_conf_set_partitioner_cb(tctx->conf, kafka_partition); rd_kafka_topic_conf_set_opaque(tctx->conf, tctx); - snprintf(callback_name, sizeof(callback_name), "write_kafka/%s", + ssnprintf(callback_name, sizeof(callback_name), "write_kafka/%s", tctx->topic_name); status = plugin_register_write( diff --git a/src/write_prometheus.c b/src/write_prometheus.c index 96e71ca1..5c745e7e 100644 --- a/src/write_prometheus.c +++ b/src/write_prometheus.c @@ -164,7 +164,7 @@ static char *format_labels(char *buffer, size_t buffer_size, * know that they are sane. */ for (size_t i = 0; i < m->n_label; i++) { char value[LABEL_VALUE_SIZE]; - snprintf(labels[i], LABEL_BUFFER_SIZE, "%s=\"%s\"", m->label[i]->name, + ssnprintf(labels[i], LABEL_BUFFER_SIZE, "%s=\"%s\"", m->label[i]->name, escape_label_value(value, sizeof(value), m->label[i]->value)); } @@ -183,10 +183,10 @@ static void format_text(ProtobufCBuffer *buffer) { while (c_avl_iterator_next(iter, (void *)&unused_name, (void *)&fam) == 0) { char line[1024]; /* 4x DATA_MAX_NAME_LEN? */ - snprintf(line, sizeof(line), "# HELP %s %s\n", fam->name, fam->help); + ssnprintf(line, sizeof(line), "# HELP %s %s\n", fam->name, fam->help); buffer->append(buffer, strlen(line), (uint8_t *)line); - snprintf(line, sizeof(line), "# TYPE %s %s\n", fam->name, + ssnprintf(line, sizeof(line), "# TYPE %s %s\n", fam->name, (fam->type == IO__PROMETHEUS__CLIENT__METRIC_TYPE__GAUGE) ? "gauge" : "counter"); @@ -199,15 +199,15 @@ static void format_text(ProtobufCBuffer *buffer) { char timestamp_ms[24] = ""; if (m->has_timestamp_ms) - snprintf(timestamp_ms, sizeof(timestamp_ms), " %" PRIi64, + ssnprintf(timestamp_ms, sizeof(timestamp_ms), " %" PRIi64, m->timestamp_ms); if (fam->type == IO__PROMETHEUS__CLIENT__METRIC_TYPE__GAUGE) - snprintf(line, sizeof(line), "%s{%s} " GAUGE_FORMAT "%s\n", fam->name, + ssnprintf(line, sizeof(line), "%s{%s} " GAUGE_FORMAT "%s\n", fam->name, format_labels(labels, sizeof(labels), m), m->gauge->value, timestamp_ms); else /* if (fam->type == IO__PROMETHEUS__CLIENT__METRIC_TYPE__COUNTER) */ - snprintf(line, sizeof(line), "%s{%s} %.0f%s\n", fam->name, + ssnprintf(line, sizeof(line), "%s{%s} %.0f%s\n", fam->name, format_labels(labels, sizeof(labels), m), m->counter->value, timestamp_ms); @@ -217,7 +217,7 @@ static void format_text(ProtobufCBuffer *buffer) { c_avl_iterator_destroy(iter); char server[1024]; - snprintf(server, sizeof(server), "\n# collectd/write_prometheus %s at %s\n", + ssnprintf(server, sizeof(server), "\n# collectd/write_prometheus %s at %s\n", PACKAGE_VERSION, hostname_g); buffer->append(buffer, strlen(server), (uint8_t *)server); @@ -635,7 +635,7 @@ metric_family_create(char *name, data_set_t const *ds, value_list_t const *vl, msg->name = name; char help[1024]; - snprintf( + ssnprintf( help, sizeof(help), "write_prometheus plugin: '%s' Type: '%s', Dstype: '%s', Dsname: '%s'", vl->plugin, vl->type, DS_TYPE_TO_STRING(ds->ds[ds_index].type), @@ -744,7 +744,7 @@ static void prom_logger(__attribute__((unused)) void *arg, char const *fmt, static int prom_open_socket(int addrfamily) { /* {{{ */ char service[NI_MAXSERV]; - snprintf(service, sizeof(service), "%hu", httpd_port); + ssnprintf(service, sizeof(service), "%hu", httpd_port); struct addrinfo *res; int status = getaddrinfo(httpd_host, service, diff --git a/src/write_redis.c b/src/write_redis.c index 324999c1..d8cc94fd 100644 --- a/src/write_redis.c +++ b/src/write_redis.c @@ -71,9 +71,9 @@ static int wr_write(const data_set_t *ds, /* {{{ */ status = FORMAT_VL(ident, sizeof(ident), vl); if (status != 0) return status; - snprintf(key, sizeof(key), "%s%s", + ssnprintf(key, sizeof(key), "%s%s", (node->prefix != NULL) ? node->prefix : REDIS_DEFAULT_PREFIX, ident); - snprintf(time, sizeof(time), "%.9f", CDTIME_T_TO_DOUBLE(vl->time)); + ssnprintf(time, sizeof(time), "%.9f", CDTIME_T_TO_DOUBLE(vl->time)); value_size = sizeof(value); value_ptr = &value[0]; @@ -239,7 +239,7 @@ static int wr_config_node(oconfig_item_t *ci) /* {{{ */ if (status == 0) { char cb_name[sizeof("write_redis/") + DATA_MAX_NAME_LEN]; - snprintf(cb_name, sizeof(cb_name), "write_redis/%s", node->name); + ssnprintf(cb_name, sizeof(cb_name), "write_redis/%s", node->name); status = plugin_register_write(cb_name, wr_write, diff --git a/src/write_riemann.c b/src/write_riemann.c index 62ddc67c..c6507572 100644 --- a/src/write_riemann.c +++ b/src/write_riemann.c @@ -291,16 +291,16 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */ vl->type_instance); if (host->always_append_ds || (ds->ds_num > 1)) { if (host->event_service_prefix == NULL) - snprintf(service_buffer, sizeof(service_buffer), "%s/%s", &name_buffer[1], + ssnprintf(service_buffer, sizeof(service_buffer), "%s/%s", &name_buffer[1], ds->ds[index].name); else - snprintf(service_buffer, sizeof(service_buffer), "%s%s/%s", + ssnprintf(service_buffer, sizeof(service_buffer), "%s%s/%s", host->event_service_prefix, &name_buffer[1], ds->ds[index].name); } else { if (host->event_service_prefix == NULL) sstrncpy(service_buffer, &name_buffer[1], sizeof(service_buffer)); else - snprintf(service_buffer, sizeof(service_buffer), "%s%s", + ssnprintf(service_buffer, sizeof(service_buffer), "%s%s", host->event_service_prefix, &name_buffer[1]); } @@ -349,7 +349,7 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */ if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL)) { char ds_type[DATA_MAX_NAME_LEN]; - snprintf(ds_type, sizeof(ds_type), "%s:rate", + ssnprintf(ds_type, sizeof(ds_type), "%s:rate", DS_TYPE_TO_STRING(ds->ds[index].type)); riemann_event_string_attribute_add(event, "ds_type", ds_type); } else { @@ -360,7 +360,7 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */ { char ds_index[DATA_MAX_NAME_LEN]; - snprintf(ds_index, sizeof(ds_index), "%" PRIsz, index); + ssnprintf(ds_index, sizeof(ds_index), "%" PRIsz, index); riemann_event_string_attribute_add(event, "ds_index", ds_index); } @@ -777,7 +777,7 @@ static int wrr_config_node(oconfig_item_t *ci) /* {{{ */ return status; } - snprintf(callback_name, sizeof(callback_name), "write_riemann/%s", + ssnprintf(callback_name, sizeof(callback_name), "write_riemann/%s", host->name); user_data_t ud = {.data = host, .free_func = wrr_free}; diff --git a/src/write_stackdriver.c b/src/write_stackdriver.c index fd0192a0..46d9aa8c 100644 --- a/src/write_stackdriver.c +++ b/src/write_stackdriver.c @@ -109,7 +109,7 @@ static char *wg_get_authorization_header(wg_callback_t *cb) { /* {{{ */ return NULL; } - status = snprintf(authorization_header, sizeof(authorization_header), + status = ssnprintf(authorization_header, sizeof(authorization_header), "Authorization: Bearer %s", access_token); if ((status < 1) || ((size_t)status >= sizeof(authorization_header))) return NULL; @@ -160,9 +160,9 @@ static char *api_error_string(api_error_t *err, char *buffer, if (err == NULL) { strncpy(buffer, "Unknown error (API error is NULL)", buffer_size); } else if (err->message == NULL) { - snprintf(buffer, buffer_size, "API error %d", err->code); + ssnprintf(buffer, buffer_size, "API error %d", err->code); } else { - snprintf(buffer, buffer_size, "API error %d: %s", err->code, err->message); + ssnprintf(buffer, buffer_size, "API error %d: %s", err->code, err->message); } return buffer; @@ -251,7 +251,7 @@ static int do_post(wg_callback_t *cb, char const *url, void const *payload, static int wg_call_metricdescriptor_create(wg_callback_t *cb, char const *payload) { char url[1024]; - snprintf(url, sizeof(url), "%s/projects/%s/metricDescriptors", cb->url, + ssnprintf(url, sizeof(url), "%s/projects/%s/metricDescriptors", cb->url, cb->project); wg_memory_t response = {0}; @@ -273,7 +273,7 @@ static int wg_call_metricdescriptor_create(wg_callback_t *cb, static int wg_call_timeseries_write(wg_callback_t *cb, char const *payload) { char url[1024]; - snprintf(url, sizeof(url), "%s/projects/%s/timeSeries", cb->url, cb->project); + ssnprintf(url, sizeof(url), "%s/projects/%s/timeSeries", cb->url, cb->project); wg_memory_t response = {0}; int status = do_post(cb, url, payload, &response); diff --git a/src/zfs_arc.c b/src/zfs_arc.c index d18a93f7..a3c24516 100644 --- a/src/zfs_arc.c +++ b/src/zfs_arc.c @@ -127,7 +127,7 @@ static long long get_zfs_value(kstat_t *dummy __attribute__((unused)), size_t valuelen = sizeof(value); int rv; - snprintf(buffer, sizeof(buffer), "%s%s", zfs_arcstat, name); + ssnprintf(buffer, sizeof(buffer), "%s%s", zfs_arcstat, name); rv = sysctlbyname(buffer, (void *)&value, &valuelen, /* new value = */ NULL, /* new length = */ (size_t)0); if (rv == 0) -- 2.11.0