summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozsef Kadlecsik <kadlec@netfilter.org>2025-04-18 15:40:47 +0200
committerJozsef Kadlecsik <kadlec@netfilter.org>2025-04-18 15:40:47 +0200
commit558c6cf67659d5fdc9383b83454dbd4964833579 (patch)
treec8ef97c2f8937ba96ea7ed597d7e357a822927f1
parent58efd98188004c5cc9e7ad195f69e098966039d8 (diff)
Fix unquoted port range in json output
Fixes bugzilla #1793, issue 1. Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
-rw-r--r--lib/print.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/print.c b/lib/print.c
index 3806e1c..a95ee4f 100644
--- a/lib/print.c
+++ b/lib/print.c
@@ -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);
}