From: Jozsef Kadlecsik Date: Fri, 18 Apr 2025 13:40:47 +0000 (+0200) Subject: Fix unquoted port range in json output X-Git-Tag: v7.24~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=558c6cf67659d5fdc9383b83454dbd4964833579;p=thirdparty%2Fipset.git Fix unquoted port range in json output Fixes bugzilla #1793, issue 1. Signed-off-by: Jozsef Kadlecsik --- 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); }