-
Notifications
You must be signed in to change notification settings - Fork 18
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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); | ||
free(*ns); | ||
*ns = strdup(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)++); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check this result. and if possible dereference |
||
} | ||
} | ||
return 0; | ||
|
@@ -1157,4 +1152,4 @@ static int cmt_decode_prometheus_error(void *yyscanner, | |
{ | ||
report_error(context, CMT_DECODE_PROMETHEUS_SYNTAX_ERROR, msg); | ||
return 0; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check this result.