]> git.ipfire.org Git - thirdparty/ipset.git/commitdiff
Fix unquoted port range in json output
authorJozsef Kadlecsik <kadlec@netfilter.org>
Fri, 18 Apr 2025 13:40:47 +0000 (15:40 +0200)
committerJozsef Kadlecsik <kadlec@netfilter.org>
Fri, 18 Apr 2025 13:40:47 +0000 (15:40 +0200)
Fixes bugzilla #1793, issue 1.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
lib/print.c

index 3806e1c04736beb2541680926f1c654274c218d0..a95ee4fdda68ed63005848379586a09c2a7f67b2 100644 (file)
@@ -518,10 +518,12 @@ int
 ipset_print_port(char *buf, unsigned int len,
                 const struct ipset_data *data,
                 enum ipset_opt opt ASSERT_UNUSED,
-                uint8_t env UNUSED)
+                uint8_t env)
 {
        const uint16_t *port;
        int size, offset = 0;
+       const char *quoted = ipset_data_test(data, IPSET_OPT_PORT_TO) &&
+                            env & IPSET_ENV_QUOTED ? "\"" : "";
 
        assert(buf);
        assert(len > 0);
@@ -533,14 +535,14 @@ ipset_print_port(char *buf, unsigned int len,
 
        port = ipset_data_get(data, IPSET_OPT_PORT);
        assert(port);
-       size = snprintf(buf, len, "%u", *port);
+       size = snprintf(buf, len, "%s%u", quoted, *port);
        SNPRINTF_FAILURE(size, len, offset);
 
        if (ipset_data_test(data, IPSET_OPT_PORT_TO)) {
                port = ipset_data_get(data, IPSET_OPT_PORT_TO);
                size = snprintf(buf + offset, len,
-                               "%s%u",
-                               IPSET_RANGE_SEPARATOR, *port);
+                               "%s%u%s",
+                               IPSET_RANGE_SEPARATOR, *port, quoted);
                SNPRINTF_FAILURE(size, len, offset);
        }