]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
gprint: fix comma after ip addresses
authorCorubba Smith <corubba@gmx.de>
Sun, 16 Feb 2025 14:03:51 +0000 (15:03 +0100)
committerFlorian Westphal <fw@strlen.de>
Tue, 11 Mar 2025 15:15:29 +0000 (16:15 +0100)
Do the same as the oprint plugin: let inet_ntop() write to a temporary
buffer, and then write that buffer content and the trailing comma to the
actual output buffer in one go.

Fixes: f04bf6794d11 ("gprint, oprint: use inet_ntop to format ip addresses")
Signed-off-by: Corubba Smith <corubba@gmx.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
output/ulogd_output_GPRINT.c

index 37829fa49e9d9b0156d4349375e012a5627d3b99..20dd30807a328529c407a4cb103feff19bfceb3d 100644 (file)
@@ -155,6 +155,7 @@ static int gprint_interp(struct ulogd_pluginstance *upi)
                        size += ret;
                        break;
                case ULOGD_RET_IPADDR: {
+                       char addrbuf[INET6_ADDRSTRLEN + 1] = "";
                        struct in6_addr ipv6addr;
                        struct in_addr ipv4addr;
                        int family;
@@ -176,10 +177,12 @@ static int gprint_interp(struct ulogd_pluginstance *upi)
                                addr = &ipv4addr;
                                family = AF_INET;
                        }
-                       if (!inet_ntop(family, addr, buf + size, rem))
+                       if (!inet_ntop(family, addr, addrbuf, sizeof(addrbuf)))
                                break;
-                       ret = strlen(buf + size);
 
+                       ret = snprintf(buf+size, rem, "%s,", addrbuf);
+                       if (ret < 0)
+                               break;
                        rem -= ret;
                        size += ret;
                        break;