From: Marc Fournier Date: Fri, 5 Feb 2016 14:16:09 +0000 (+0100) Subject: write_sensu: avoid calling strlen() on variable set to NULL X-Git-Tag: collectd-5.5.2~64^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fa9635edea38401727b81e176f035a8c9d6b7bc6;p=collectd.git write_sensu: avoid calling strlen() on variable set to NULL This fixes a segfault when no `Tag` option is set. --- diff --git a/src/write_sensu.c b/src/write_sensu.c index 507018fd..4d0e4737 100644 --- a/src/write_sensu.c +++ b/src/write_sensu.c @@ -456,7 +456,7 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */ } // incorporate sensu tags from config if any - if (strlen(sensu_tags) != 0) { + if ((sensu_tags != NULL) && (strlen(sensu_tags) != 0)) { res = asprintf(&temp_str, "%s, %s", ret_str, sensu_tags); free(ret_str); if (res == -1) { @@ -753,7 +753,7 @@ static char *sensu_notification_to_json(struct sensu_host *host, /* {{{ */ } // incorporate sensu tags from config if any - if (strlen(sensu_tags) != 0) { + if ((sensu_tags != NULL) && (strlen(sensu_tags) != 0)) { res = asprintf(&temp_str, "%s, %s", ret_str, sensu_tags); free(ret_str); if (res == -1) {