diff --git a/plugins/processor_content_modifier/cm_logs.c b/plugins/processor_content_modifier/cm_logs.c index 98d2bcfd081..8718cc8d939 100644 --- a/plugins/processor_content_modifier/cm_logs.c +++ b/plugins/processor_content_modifier/cm_logs.c @@ -84,9 +84,8 @@ static int hash_transformer(void *context, struct cfl_variant *value) return FLB_FALSE; } - if (cfl_sds_len(converted_value->data.as_string) == 0) { + if (cfl_variant_size_get(converted_value) == 0) { cfl_variant_destroy(converted_value); - return FLB_TRUE; } @@ -118,9 +117,12 @@ static int hash_transformer(void *context, struct cfl_variant *value) return FLB_FALSE; } + /* NOTE: this part does a manual modification of the variant content */ if (value->type == CFL_VARIANT_STRING || value->type == CFL_VARIANT_BYTES) { - cfl_sds_destroy(value->data.as_string); + if (value->referenced == CFL_FALSE) { + cfl_sds_destroy(value->data.as_string); + } } else if (value->type == CFL_VARIANT_ARRAY) { cfl_array_destroy(value->data.as_array); @@ -131,6 +133,7 @@ static int hash_transformer(void *context, struct cfl_variant *value) value->type = CFL_VARIANT_STRING; value->data.as_string = encoded_hash; + cfl_variant_size_set(value, cfl_sds_len(encoded_hash)); return FLB_TRUE; } @@ -178,7 +181,8 @@ int cfl_variant_convert(struct cfl_variant *input_value, output_type == CFL_VARIANT_BYTES) { tmp = cfl_variant_create_from_string_s(input_value->data.as_string, - cfl_sds_len(input_value->data.as_string)); + cfl_variant_size_get(input_value), + CFL_FALSE); if (!tmp) { return CFL_FALSE; } @@ -232,7 +236,7 @@ int cfl_variant_convert(struct cfl_variant *input_value, if (ret < 0 || ret >= sizeof(buf)) { return CFL_FALSE; } - tmp = cfl_variant_create_from_string_s(buf, ret); + tmp = cfl_variant_create_from_string_s(buf, ret, CFL_FALSE); } else if (output_type == CFL_VARIANT_BOOL) { as_int = CFL_FALSE; @@ -261,7 +265,7 @@ int cfl_variant_convert(struct cfl_variant *input_value, if (ret < 0 || ret >= sizeof(buf)) { return CFL_FALSE; } - tmp = cfl_variant_create_from_string_s(buf, ret); + tmp = cfl_variant_create_from_string_s(buf, ret, CFL_FALSE); } else if (output_type == CFL_VARIANT_BOOL) { as_int = CFL_FALSE; @@ -288,7 +292,7 @@ int cfl_variant_convert(struct cfl_variant *input_value, if (output_type == CFL_VARIANT_STRING || output_type == CFL_VARIANT_BYTES) { - tmp = cfl_variant_create_from_string_s("null", 4); + tmp = cfl_variant_create_from_string_s("null", 4, CFL_FALSE); } else if (output_type == CFL_VARIANT_BOOL) { tmp = cfl_variant_create_from_bool(CFL_FALSE); @@ -350,7 +354,8 @@ static int run_action_insert(struct content_modifier_ctx *ctx, /* insert the new value */ kvlist = obj->variant->data.as_kvlist; - ret = cfl_kvlist_insert_string_s(kvlist, key, cfl_sds_len(key), value, cfl_sds_len(value)); + ret = cfl_kvlist_insert_string_s(kvlist, key, cfl_sds_len(key), value, cfl_sds_len(value), + CFL_FALSE); if (ret != 0) { printf("Failed to insert key: %s\n", key); return -1; @@ -376,7 +381,8 @@ static int run_action_upsert(struct content_modifier_ctx *ctx, } /* insert the key with the updated value */ - ret = cfl_kvlist_insert_string_s(kvlist, key, cfl_sds_len(key), value, cfl_sds_len(value)); + ret = cfl_kvlist_insert_string_s(kvlist, key, cfl_sds_len(key), value, cfl_sds_len(value), + CFL_FALSE); if (ret != 0) { return -1; } @@ -461,7 +467,8 @@ static void cb_extract_regex(const char *name, const char *value, size_t value_l cfl_kvlist_remove(kvlist, (char *) name); } - cfl_kvlist_insert_string_s(kvlist, (char *) name, strlen(name), (char *) value, value_length); + cfl_kvlist_insert_string_s(kvlist, (char *) name, strlen(name), (char *) value, value_length, + CFL_FALSE); } int run_action_extract(struct content_modifier_ctx *ctx, @@ -489,7 +496,9 @@ int run_action_extract(struct content_modifier_ctx *ctx, return -1; } - match_count = flb_regex_do(regex, v->data.as_string, cfl_sds_len(v->data.as_string), &match_list); + match_count = flb_regex_do(regex, + v->data.as_string, + cfl_variant_size_get(v), &match_list); if (match_count <= 0) { return -1; }