Skip to content

Commit

Permalink
Merge pull request #328 from MrAnno/axosyslog-otlp-fix-addr
Browse files Browse the repository at this point in the history
otel-dest: fix crash when message contains GSockAddrUnix
  • Loading branch information
alltilla authored Oct 7, 2024
2 parents bf33930 + 21df5a1 commit 5669801
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/gsockaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,17 @@ g_sockaddr_inet_or_inet6_new(const gchar *name, guint16 port)
return addr;
}

gboolean
g_sockaddr_inet_or_inet6_check(GSockAddr *a)
{
#if SYSLOG_NG_ENABLE_IPV6
if (G_UNLIKELY(g_sockaddr_inet6_check(a)))
return TRUE;
#endif

return g_sockaddr_inet_check(a);
}

/* AF_UNIX socket address */

/*+
Expand Down
1 change: 1 addition & 0 deletions lib/gsockaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ gboolean g_sockaddr_inet6_is_v4_mapped(GSockAddr *s);
#endif

GSockAddr *g_sockaddr_inet_or_inet6_new(const gchar *name, guint16 port);
gboolean g_sockaddr_inet_or_inet6_check(GSockAddr *a);

GSockAddr *g_sockaddr_unix_new(const gchar *name);
GSockAddr *g_sockaddr_unix_new2(struct sockaddr_un *s_un, int sunlen);
Expand Down
4 changes: 2 additions & 2 deletions modules/grpc/otel/otel-protobuf-formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,14 +582,14 @@ ProtobufFormatter::set_syslog_ng_addresses(LogMessage *msg, LogRecord &log_recor
{
/* source address */

if (msg->saddr)
if (msg->saddr && g_sockaddr_inet_or_inet6_check(msg->saddr))
{
KeyValue *sa = log_record.add_attributes();
sa->set_key("sa");
set_syslog_ng_address_attrs(msg->saddr, sa->mutable_value()->mutable_kvlist_value(), false);
}

if (msg->daddr)
if (msg->daddr && g_sockaddr_inet_or_inet6_check(msg->daddr))
{
/* dest address */
KeyValue *da = log_record.add_attributes();
Expand Down

0 comments on commit 5669801

Please sign in to comment.