projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ntpd plugin: Fix two format strings.
[collectd.git]
/
src
/
utils_cmd_putval.c
diff --git
a/src/utils_cmd_putval.c
b/src/utils_cmd_putval.c
index
7cf0b6d
..
e5f7495
100644
(file)
--- a/
src/utils_cmd_putval.c
+++ b/
src/utils_cmd_putval.c
@@
-36,7
+36,7
@@
static int parse_value (const data_set_t *ds, value_list_t *vl,
char *value_str = strchr (time_str, ':');
if (value_str == NULL)
{
char *value_str = strchr (time_str, ':');
if (value_str == NULL)
{
- fprintf (fh, "-1 No time found.");
+ fprintf (fh, "-1 No time found.
\n
");
return (-1);
}
*value_str = '\0'; value_str++;
return (-1);
}
*value_str = '\0'; value_str++;
@@
-121,6
+121,8
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
int status;
int i;
int status;
int i;
+ char *identifier_copy;
+
const data_set_t *ds;
value_list_t vl = VALUE_LIST_INIT;
const data_set_t *ds;
value_list_t vl = VALUE_LIST_INIT;
@@
-135,7
+137,11
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
return (-1);
}
return (-1);
}
- status = parse_identifier (fields[1], &hostname,
+ /* parse_identifier() modifies its first argument,
+ * returning pointers into it */
+ identifier_copy = sstrdup (fields[1]);
+
+ status = parse_identifier (identifier_copy, &hostname,
&plugin, &plugin_instance,
&type, &type_instance);
if (status != 0)
&plugin, &plugin_instance,
&type, &type_instance);
if (status != 0)
@@
-143,6
+149,7
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
DEBUG ("cmd putval: Cannot parse `%s'", fields[1]);
fprintf (fh, "-1 Cannot parse identifier.\n");
fflush (fh);
DEBUG ("cmd putval: Cannot parse `%s'", fields[1]);
fprintf (fh, "-1 Cannot parse identifier.\n");
fflush (fh);
+ sfree (identifier_copy);
return (-1);
}
return (-1);
}
@@
-153,26
+160,32
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
|| ((type_instance != NULL)
&& (strlen (type_instance) >= sizeof (vl.type_instance))))
{
|| ((type_instance != NULL)
&& (strlen (type_instance) >= sizeof (vl.type_instance))))
{
- fprintf (fh, "-1 Identifier too long.");
+ fprintf (fh, "-1 Identifier too long.\n");
+ fflush (fh);
+ sfree (identifier_copy);
return (-1);
}
return (-1);
}
- s
trcpy (vl.host, hostname
);
- s
trcpy (vl.plugin, plugin
);
+ s
strncpy (vl.host, hostname, sizeof (vl.host)
);
+ s
strncpy (vl.plugin, plugin, sizeof (vl.plugin)
);
if (plugin_instance != NULL)
if (plugin_instance != NULL)
- s
trcpy (vl.plugin_instance, plugin_instance
);
+ s
strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)
);
if (type_instance != NULL)
if (type_instance != NULL)
- s
trcpy (vl.type_instance, type_instance
);
+ s
strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)
);
ds = plugin_get_ds (type);
ds = plugin_get_ds (type);
- if (ds == NULL)
+ if (ds == NULL) {
+ sfree (identifier_copy);
return (-1);
return (-1);
+ }
vl.values_len = ds->ds_num;
vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t));
if (vl.values == NULL)
{
vl.values_len = ds->ds_num;
vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t));
if (vl.values == NULL)
{
- fprintf (fh, "-1 malloc failed.");
+ fprintf (fh, "-1 malloc failed.\n");
+ fflush (fh);
+ sfree (identifier_copy);
return (-1);
}
return (-1);
}
@@
-191,7
+204,7
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
{
if (parse_option (&vl, fields[i]) != 0)
{
{
if (parse_option (&vl, fields[i]) != 0)
{
- fprintf (fh, "-1 Error parsing option `%s'",
+ fprintf (fh, "-1 Error parsing option `%s'
\n
",
fields[i]);
break;
}
fields[i]);
break;
}
@@
-211,6
+224,7
@@
int handle_putval (FILE *fh, char **fields, int fields_num)
fflush (fh);
sfree (vl.values);
fflush (fh);
sfree (vl.values);
+ sfree (identifier_copy);
return (0);
} /* int handle_putval */
return (0);
} /* int handle_putval */