Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decode: prometheus: fix to avoid freeing non-malloced data #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/cmt_decode_prometheus.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,8 @@ static void reset_context(struct cmt_decode_prometheus_context *context,
}

if (context->metric.ns) {
if (strcmp(context->metric.ns, "")) {
/* when namespace is empty, "name" contains a pointer to the
* allocated string */
free(context->metric.ns);
}
else {
free(context->metric.name);
}
free(context->metric.ns);
free(context->metric.name);
}

cfl_sds_destroy(context->strbuf);
Expand Down Expand Up @@ -166,20 +160,21 @@ static int split_metric_name(struct cmt_decode_prometheus_context *context,
}
*subsystem = strchr(*ns, '_');
if (!(*subsystem)) {
*name = *ns;
*ns = "";
*name = strdup(*ns);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check this result.

free(*ns);
*ns = strdup("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check this result.

}
else {
**subsystem = 0; /* split */
(*subsystem)++;
*name = strchr(*subsystem, '_');
if (!(*name)) {
*name = *subsystem;
*name = strdup(*subsystem);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check this result.

*subsystem = "";
}
else {
**name = 0;
(*name)++;
**name = '\0';
*name = strdup((*name)++);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check this result. and if possible dereference name in this way (*name)[1].

}
}
return 0;
Expand Down Expand Up @@ -1157,4 +1152,4 @@ static int cmt_decode_prometheus_error(void *yyscanner,
{
report_error(context, CMT_DECODE_PROMETHEUS_SYNTAX_ERROR, msg);
return 0;
}
}