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_nest: define a new var to prevent pointer arithmetic #8454

Merged
merged 1 commit into from
Mar 17, 2024
Merged
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
12 changes: 11 additions & 1 deletion plugins/filter_nest/nest.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,19 @@ static void helper_pack_string_add_prefix(struct flb_log_event_encoder *log_enco
const char *str,
int len)
{
size_t new_size;

/*
An arg of FLB_LOG_EVENT_STRING_LENGTH_VALUE is a flb_log_event_encoder_size_t.
flb_log_event_encoder_size_t is size_t* on Windows.
It can cause pointer arithmetic and the output can be larger value.
We use 'new_size' to prevent pointer arithmetic.
*/
new_size = ctx->prefix_len + len;

flb_log_event_encoder_append_body_values(
log_encoder,
FLB_LOG_EVENT_STRING_LENGTH_VALUE(ctx->prefix_len + len),
FLB_LOG_EVENT_STRING_LENGTH_VALUE(new_size),
FLB_LOG_EVENT_STRING_BODY_VALUE(ctx->prefix, ctx->prefix_len),
FLB_LOG_EVENT_STRING_BODY_VALUE(str, len));
}
Expand Down
Loading