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

filter_logs_to_metrics: fixed memory corruption issue #9252

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
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
17 changes: 10 additions & 7 deletions plugins/filter_log_to_metrics/log_to_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ static int cb_log_to_metrics_init(struct flb_filter_instance *f_ins,
char value_field[MAX_METRIC_LENGTH];
struct flb_input_instance *input_ins;


int i;
/* Create context */
ctx = flb_calloc(1, sizeof(struct log_to_metrics_ctx));
Expand Down Expand Up @@ -551,15 +552,17 @@ static int cb_log_to_metrics_init(struct flb_filter_instance *f_ins,

/* Check property metric mode */
ctx->mode = 0;
tmp = (char *) flb_filter_get_property("metric_mode", f_ins);
if (tmp != NULL) {
if (strcasecmp(tmp, FLB_LOG_TO_METRICS_COUNTER_STR) == 0) {
if (ctx->mode_name != NULL) {
if (strcasecmp(ctx->mode_name,
FLB_LOG_TO_METRICS_COUNTER_STR) == 0) {
ctx->mode = FLB_LOG_TO_METRICS_COUNTER;
}
else if (strcasecmp(tmp, FLB_LOG_TO_METRICS_GAUGE_STR) == 0) {
else if (strcasecmp(ctx->mode_name,
FLB_LOG_TO_METRICS_GAUGE_STR) == 0) {
ctx->mode = FLB_LOG_TO_METRICS_GAUGE;
}
else if (strcasecmp(tmp, FLB_LOG_TO_METRICS_HISTOGRAM_STR) == 0) {
else if (strcasecmp(ctx->mode_name,
FLB_LOG_TO_METRICS_HISTOGRAM_STR) == 0) {
ctx->mode = FLB_LOG_TO_METRICS_HISTOGRAM;
}
else {
Expand Down Expand Up @@ -589,7 +592,7 @@ static int cb_log_to_metrics_init(struct flb_filter_instance *f_ins,
/* Check property subsystem name */
if (ctx->metric_subsystem == NULL || strlen(ctx->metric_subsystem) == 0) {
snprintf(metric_subsystem, sizeof(metric_subsystem) - 1, "%s",
tmp);
ctx->mode_name);
}
else {
snprintf(metric_subsystem, sizeof(metric_subsystem) - 1, "%s",
Expand Down Expand Up @@ -977,7 +980,7 @@ static struct flb_config_map config_map[] = {
},
{
FLB_CONFIG_MAP_STR, "metric_mode", "counter",
0, FLB_TRUE, offsetof(struct log_to_metrics_ctx, mode),
0, FLB_TRUE, offsetof(struct log_to_metrics_ctx, mode_name),
"Mode selector. Values counter, gauge,"
" or histogram. Summary is not supported"
},
Expand Down
1 change: 1 addition & 0 deletions plugins/filter_log_to_metrics/log_to_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct log_to_metrics_ctx {

/* config options */
int mode;
flb_sds_t mode_name;
int discard_logs;
int kubernetes_mode;
flb_sds_t metric_name;
Expand Down
Loading