Skip to content

Commit 665e4a0

Browse files
Leonardo Alminanaedsiper
authored andcommitted
in_node_exporter_metrics: fixed possible invalid dereference
Signed-off-by: Leonardo Alminana <[email protected]>
1 parent 4c95e88 commit 665e4a0

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

plugins/in_node_exporter_metrics/ne_meminfo_linux.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static int meminfo_configure(struct flb_ne *ctx)
3333
int parts;
3434
int len;
3535
char *p;
36+
flb_sds_t tmp;
3637
char desc[] = "Memory information field ";
3738
struct cmt_gauge *g;
3839
struct mk_list *head;
@@ -100,12 +101,21 @@ static int meminfo_configure(struct flb_ne *ctx)
100101

101102
/* Metric description */
102103
flb_sds_len_set(metric_desc, 0);
103-
flb_sds_cat(metric_desc, desc, sizeof(desc) - 1);
104+
ret = flb_sds_cat_safe(&metric_desc, desc, sizeof(desc) - 1);
105+
106+
if (ret != 0) {
107+
flb_slist_destroy(&split_list);
108+
goto error;
109+
}
104110

105111
if (parts == 2) {
106112
/* No unit */
107-
flb_sds_cat(metric_desc, metric_name, flb_sds_len(metric_name));
108-
flb_sds_cat(metric_desc, ".", 1);
113+
tmp = flb_sds_printf(&metric_desc, "%s.", metric_name);
114+
115+
if (tmp == NULL) {
116+
flb_slist_destroy(&split_list);
117+
goto error;
118+
}
109119

110120
g = cmt_gauge_create(ctx->cmt, "node", "memory", metric_name,
111121
metric_desc,
@@ -117,9 +127,20 @@ static int meminfo_configure(struct flb_ne *ctx)
117127
}
118128
else if (parts == 3) {
119129
/* It has an extra 'kB' string in the line */
120-
flb_sds_cat(metric_name, "_bytes", 6);
121-
flb_sds_cat(metric_desc, metric_name, flb_sds_len(metric_name));
122-
flb_sds_cat(metric_desc, ".", 1);
130+
ret = flb_sds_cat_safe(&metric_name, "_bytes", 6);
131+
132+
if (ret != 0) {
133+
flb_slist_destroy(&split_list);
134+
goto error;
135+
}
136+
137+
tmp = flb_sds_printf(&metric_desc, "%s.", metric_name);
138+
139+
if (tmp == NULL) {
140+
flb_slist_destroy(&split_list);
141+
goto error;
142+
}
143+
123144
g = cmt_gauge_create(ctx->cmt, "node", "memory", metric_name,
124145
metric_desc,
125146
0, NULL);
@@ -132,6 +153,7 @@ static int meminfo_configure(struct flb_ne *ctx)
132153
flb_slist_destroy(&split_list);
133154
continue;
134155
}
156+
135157
flb_slist_destroy(&split_list);
136158

137159
/*

0 commit comments

Comments
 (0)