Code

Merge pull request #1540 from mfournier/write_sensu_segfault_fix
authorMarc Fournier <marc.fournier@camptocamp.com>
Tue, 9 Feb 2016 22:13:15 +0000 (23:13 +0100)
committerMarc Fournier <marc.fournier@camptocamp.com>
Tue, 9 Feb 2016 22:13:15 +0000 (23:13 +0100)
write_sensu: avoid calling strlen() on variable set to NULL

src/write_sensu.c

index 507018fdd1f6a7688a0672679fdcd63628d58fe3..4d0e473757174e7bdf79b9662bbd258fa049355f 100644 (file)
@@ -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) {