X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnginx.c;h=91bcf75404927bfcd708e16faf71b5b7606fe304;hb=5b5f7f4e3dd28d9e41469c331f3f9f6a09e3147b;hp=3b107fb72ad209c41d08c22ded54fe349310d305;hpb=63c8e3eaa6260e4bf52dfe7b1927ed69447c3b93;p=collectd.git diff --git a/src/nginx.c b/src/nginx.c index 3b107fb7..91bcf754 100644 --- a/src/nginx.c +++ b/src/nginx.c @@ -122,7 +122,8 @@ static int init (void) if (user != NULL) { - if (snprintf (credentials, 1024, "%s:%s", user, pass == NULL ? "" : pass) >= 1024) + if (ssnprintf (credentials, sizeof (credentials), + "%s:%s", user, pass == NULL ? "" : pass) >= sizeof (credentials)) { ERROR ("nginx plugin: Credentials would have been truncated."); return (-1); @@ -177,17 +178,15 @@ static void submit (char *type, char *inst, long long value) vl.values = values; vl.values_len = 1; vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "nginx"); - strcpy (vl.plugin_instance, ""); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "nginx", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance)); + sstrncpy (vl.type, type, sizeof (vl.type)); if (inst != NULL) - { - strncpy (vl.type_instance, inst, sizeof (vl.type_instance)); - vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; - } + sstrncpy (vl.type_instance, inst, sizeof (vl.type_instance)); - plugin_dispatch_values (type, &vl); + plugin_dispatch_values (&vl); } /* void submit */ static int nginx_read (void) @@ -197,6 +196,7 @@ static int nginx_read (void) char *ptr; char *lines[16]; int lines_num = 0; + char *saveptr; char *fields[16]; int fields_num; @@ -214,7 +214,8 @@ static int nginx_read (void) } ptr = nginx_buffer; - while ((lines[lines_num] = strtok (ptr, "\n\r")) != NULL) + saveptr = NULL; + while ((lines[lines_num] = strtok_r (ptr, "\n\r", &saveptr)) != NULL) { ptr = NULL; lines_num++;