From: Florian Forster Date: Tue, 5 Dec 2017 15:50:33 +0000 (+0100) Subject: email plugin: Avoid strtok_r to tokenize input. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b62e57ad02538981f6fb29fe4ac8f0c701bcd1a6;p=collectd.git email plugin: Avoid strtok_r to tokenize input. Coverity (wrongly) thinks that "type" might have been NULL (since its first argument is non-NULL, this cannot happen). It has a point about insufficient NULL-ness checks, though, as "tmp" may very well be NULL and we're passing it to atoi() which will likely not take this well. CID: 37988 --- diff --git a/src/email.c b/src/email.c index d1df0a12..611da560 100644 --- a/src/email.c +++ b/src/email.c @@ -299,22 +299,21 @@ static void *collect(void *arg) { } if ('e' == line[0]) { /* e:: */ - char *ptr = NULL; - char *type = strtok_r(line + 2, ":", &ptr); - char *tmp = strtok_r(NULL, ":", &ptr); - int bytes = 0; - - if (NULL == tmp) { + char *type = line + 2; + char *bytes_str = strchr(type, ':'); + if (bytes_str == NULL) { log_err("collect: syntax error in line '%s'", line); continue; } - bytes = atoi(tmp); + *bytes_str = 0; + bytes_str++; pthread_mutex_lock(&count_mutex); type_list_incr(&list_count, type, /* increment = */ 1); pthread_mutex_unlock(&count_mutex); + int bytes = atoi(bytes_str); if (bytes > 0) { pthread_mutex_lock(&size_mutex); type_list_incr(&list_size, type, /* increment = */ bytes); @@ -374,7 +373,7 @@ static void *open_connection(void __attribute__((unused)) * arg) { } struct sockaddr_un addr = { - .sun_family = AF_UNIX + .sun_family = AF_UNIX, }; sstrncpy(addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1));