From b1af4a15d1e9aec017315aab871ec48319c90c41 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Tue, 16 Jul 2024 16:23:14 +0900 Subject: [PATCH] in_splunk: Trim spaces for the credentials Signed-off-by: Hiroshi Hatake --- plugins/in_splunk/splunk_config.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/plugins/in_splunk/splunk_config.c b/plugins/in_splunk/splunk_config.c index 135c6c53a62..a7c588658ee 100644 --- a/plugins/in_splunk/splunk_config.c +++ b/plugins/in_splunk/splunk_config.c @@ -45,8 +45,9 @@ static int setup_hec_tokens(struct flb_splunk *ctx) struct mk_list *head = NULL; struct mk_list *kvs = NULL; struct flb_split_entry *cur = NULL; - flb_sds_t auth_header; + flb_sds_t auth_header = NULL; struct flb_splunk_tokens *splunk_token; + flb_sds_t credential = NULL; raw_token = flb_input_get_property("splunk_token", ctx->ins); if (raw_token) { @@ -64,7 +65,19 @@ static int setup_hec_tokens(struct flb_splunk *ctx) goto error; } - ret = flb_sds_cat_safe(&auth_header, cur->value, strlen(cur->value)); + credential = flb_sds_create_len(cur->value, strlen(cur->value)); + if (credential == NULL) { + flb_plg_warn(ctx->ins, "error on flb_sds allocation"); + continue; + } + + ret = flb_sds_trim(credential); + if (ret == -1) { + flb_plg_warn(ctx->ins, "error on trimming for a credential candidate"); + goto error; + } + + ret = flb_sds_cat_safe(&auth_header, credential, flb_sds_len(credential)); if (ret < 0) { flb_plg_error(ctx->ins, "error on token generation"); goto error; @@ -80,6 +93,8 @@ static int setup_hec_tokens(struct flb_splunk *ctx) splunk_token->header = auth_header; splunk_token->length = flb_sds_len(auth_header); + flb_sds_destroy(credential); + /* Link to parent list */ mk_list_add(&splunk_token->_head, &ctx->auth_tokens); } @@ -97,6 +112,9 @@ static int setup_hec_tokens(struct flb_splunk *ctx) if (kvs != NULL) { flb_utils_split_free(kvs); } + if (credential != NULL) { + flb_sds_destroy(credential); + } return -1; }