Skip to content

Commit

Permalink
in_node_exporter_metrics: fixed possible invalid dereference
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Alminana <leonardo.alminana@chronosphere.io>
  • Loading branch information
leonardo-albertovich authored and edsiper committed Aug 29, 2024
1 parent 4c95e88 commit 665e4a0
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions plugins/in_node_exporter_metrics/ne_meminfo_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static int meminfo_configure(struct flb_ne *ctx)
int parts;
int len;
char *p;
flb_sds_t tmp;
char desc[] = "Memory information field ";
struct cmt_gauge *g;
struct mk_list *head;
Expand Down Expand Up @@ -100,12 +101,21 @@ static int meminfo_configure(struct flb_ne *ctx)

/* Metric description */
flb_sds_len_set(metric_desc, 0);
flb_sds_cat(metric_desc, desc, sizeof(desc) - 1);
ret = flb_sds_cat_safe(&metric_desc, desc, sizeof(desc) - 1);

if (ret != 0) {
flb_slist_destroy(&split_list);
goto error;
}

if (parts == 2) {
/* No unit */
flb_sds_cat(metric_desc, metric_name, flb_sds_len(metric_name));
flb_sds_cat(metric_desc, ".", 1);
tmp = flb_sds_printf(&metric_desc, "%s.", metric_name);

if (tmp == NULL) {
flb_slist_destroy(&split_list);
goto error;
}

g = cmt_gauge_create(ctx->cmt, "node", "memory", metric_name,
metric_desc,
Expand All @@ -117,9 +127,20 @@ static int meminfo_configure(struct flb_ne *ctx)
}
else if (parts == 3) {
/* It has an extra 'kB' string in the line */
flb_sds_cat(metric_name, "_bytes", 6);
flb_sds_cat(metric_desc, metric_name, flb_sds_len(metric_name));
flb_sds_cat(metric_desc, ".", 1);
ret = flb_sds_cat_safe(&metric_name, "_bytes", 6);

if (ret != 0) {
flb_slist_destroy(&split_list);
goto error;
}

tmp = flb_sds_printf(&metric_desc, "%s.", metric_name);

if (tmp == NULL) {
flb_slist_destroy(&split_list);
goto error;
}

g = cmt_gauge_create(ctx->cmt, "node", "memory", metric_name,
metric_desc,
0, NULL);
Expand All @@ -132,6 +153,7 @@ static int meminfo_configure(struct flb_ne *ctx)
flb_slist_destroy(&split_list);
continue;
}

flb_slist_destroy(&split_list);

/*
Expand Down

0 comments on commit 665e4a0

Please sign in to comment.