]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
rule, set_elem: fix printing of user data
authorJeremy Sowden <jeremy@azazel.net>
Sat, 27 Aug 2022 17:17:17 +0000 (18:17 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 29 Aug 2022 07:54:41 +0000 (09:54 +0200)
Hitherto, alphanumeric characters have been printed as-is, but anything
else was replaced by '\0'.  However, this effectively truncates the
output.  Instead, print any printable character as-is and print anything
else as a hexadecimal escape sequence:

  userdata = { \x01\x04\x01\x00\x00\x00 }

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/rule.c
src/set_elem.c

index 0bb1c2a0583c18a9e0415c4b80f0aee2ee8c719b..a1a64bd2837d9966efbf406217c461c70ad98c3e 100644 (file)
@@ -622,8 +622,9 @@ static int nftnl_rule_snprintf_default(char *buf, size_t remain,
                for (i = 0; i < r->user.len; i++) {
                        char *c = r->user.data;
 
-                       ret = snprintf(buf + offset, remain, "%c",
-                                      isalnum(c[i]) ? c[i] : 0);
+                       ret = snprintf(buf + offset, remain,
+                                      isprint(c[i]) ? "%c" : "\\x%02hhx",
+                                      c[i]);
                        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                }
 
index 95009acb17dc3135ebe6a7da43246dc2a0b85ebf..1c8720dc7c57a3a8c503e7db24f1068dbcda55c8 100644 (file)
@@ -735,14 +735,15 @@ int nftnl_set_elem_snprintf_default(char *buf, size_t remain,
        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
        if (e->user.len) {
-               ret = snprintf(buf + offset, remain, "  userdata = {");
+               ret = snprintf(buf + offset, remain, "  userdata = { ");
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
                for (i = 0; i < e->user.len; i++) {
                        char *c = e->user.data;
 
-                       ret = snprintf(buf + offset, remain, "%c",
-                                      isalnum(c[i]) ? c[i] : 0);
+                       ret = snprintf(buf + offset, remain,
+                                      isprint(c[i]) ? "%c" : "\\x%02hhx",
+                                      c[i]);
                        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                }