Skip to content

Commit

Permalink
processor_content_modifier: use copied values for referenced values w…
Browse files Browse the repository at this point in the history
…hen converting

Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Apr 18, 2024
1 parent 8bf039b commit 76b99fc
Showing 1 changed file with 54 additions and 7 deletions.
61 changes: 54 additions & 7 deletions plugins/processor_content_modifier/cm_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ static int hash_transformer(void *context, struct cfl_variant *value)

value->type = CFL_VARIANT_STRING;
value->data.as_string = encoded_hash;
value->referenced = CFL_FALSE;

cfl_variant_size_set(value, cfl_sds_len(encoded_hash));

return FLB_TRUE;
Expand Down Expand Up @@ -164,12 +166,13 @@ int cfl_variant_convert(struct cfl_variant *input_value,
int output_type)
{
int ret;
int errno_backup;
int64_t as_int;
char buf[64];
double as_double;
char *converstion_canary;
char buf[64];
char *str = NULL;
char *converstion_canary = NULL;
struct cfl_variant *tmp = NULL;
int errno_backup;

errno_backup = errno;

Expand All @@ -190,34 +193,78 @@ int cfl_variant_convert(struct cfl_variant *input_value,
else if (output_type == CFL_VARIANT_BOOL) {
as_int = CFL_FALSE;

if (strcasecmp(input_value->data.as_string, "true") == 0) {
if (cfl_variant_size_get(input_value) == 4 &&
strncasecmp(input_value->data.as_string, "true", 4) == 0) {
as_int = CFL_TRUE;
}
else if (strcasecmp(input_value->data.as_string, "false") == 0) {
else if (cfl_variant_size_get(input_value) == 5 &&
strncasecmp(input_value->data.as_string, "false", 5) == 0) {
as_int = CFL_FALSE;
}

tmp = cfl_variant_create_from_bool(as_int);
}
else if (output_type == CFL_VARIANT_INT) {
errno = 0;
as_int = strtoimax(input_value->data.as_string, &converstion_canary, 10);

if (input_value->referenced) {
tmp = cfl_variant_create_from_string_s(input_value->data.as_string,
cfl_variant_size_get(input_value),
CFL_FALSE);
if (!tmp) {
return CFL_FALSE;
}
str = tmp->data.as_string;
}
else {
str = input_value->data.as_string;
}

as_int = strtoimax(str, &converstion_canary, 10);
if (errno == ERANGE || errno == EINVAL) {
errno = errno_backup;
if (tmp) {
cfl_variant_destroy(tmp);
}
return CFL_FALSE;
}

if (tmp) {
cfl_variant_destroy(tmp);
}

tmp = cfl_variant_create_from_int64(as_int);
}
else if (output_type == CFL_VARIANT_DOUBLE) {
errno = 0;
converstion_canary = NULL;
as_double = strtod(input_value->data.as_string, &converstion_canary);

if (input_value->referenced) {
tmp = cfl_variant_create_from_string_s(input_value->data.as_string,
cfl_variant_size_get(input_value),
CFL_FALSE);
if (!tmp) {
return CFL_FALSE;
}
str = tmp->data.as_string;
}
else {
str = input_value->data.as_string;
}

as_double = strtod(str, &converstion_canary);
if (errno == ERANGE) {
errno = errno_backup;
if (tmp) {
cfl_variant_destroy(tmp);
}
return CFL_FALSE;
}

if (tmp) {
cfl_variant_destroy(tmp);
}

if (as_double == 0 && converstion_canary == input_value->data.as_string) {
errno = errno_backup;
return CFL_FALSE;
Expand Down

0 comments on commit 76b99fc

Please sign in to comment.