Skip to content

Commit

Permalink
filterx/object-message-value: ensure that an extra NUL character is p…
Browse files Browse the repository at this point in the history
…resent

Macro based values are captured into an allocated buffer in
FilterXMessageValue, but there was no extra NUL character added in case
repr_len was specified (which is for any log_msg_get_value() resolutions).

This causes valgrind to throw errors when the APPEND_ZERO() macro is used.

Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed Jan 3, 2025
1 parent 6cf486f commit f00094d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/filterx/object-message-value.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,11 @@ FilterXObject *
filterx_message_value_new(const gchar *repr, gssize repr_len, LogMessageValueType type)
{
gssize len = repr_len < 0 ? strlen(repr) : repr_len;
gssize alloc_len = repr_len < 0 ? len + 1 : repr_len;
gchar *buf = g_memdup2(repr, alloc_len);

/* NOTE: always add a zero byte to the end, even if length was specified */
gchar *buf = g_malloc(len + 1);
memcpy(buf, repr, len);
buf[len] = 0;
FilterXMessageValue *self = (FilterXMessageValue *) filterx_message_value_new_borrowed(buf, len, type);
self->buf = buf;
return &self->super;
Expand Down

0 comments on commit f00094d

Please sign in to comment.