62 lines
1.9 KiB
Diff
62 lines
1.9 KiB
Diff
From 212479ad2c9200fa858a37de14a2e5e996f10105 Mon Sep 17 00:00:00 2001
|
|
From: Jeremy Sowden <jeremy@azazel.net>
|
|
Date: Sat, 27 Aug 2022 18:17:17 +0100
|
|
Subject: [PATCH] rule, set_elem: fix printing of user data
|
|
|
|
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 | 5 +++--
|
|
src/set_elem.c | 7 ++++---
|
|
2 files changed, 7 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/src/rule.c b/src/rule.c
|
|
index 0bb1c2a..a1a64bd 100644
|
|
--- a/src/rule.c
|
|
+++ b/src/rule.c
|
|
@@ -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);
|
|
}
|
|
|
|
diff --git a/src/set_elem.c b/src/set_elem.c
|
|
index 90632a2..104719b 100644
|
|
--- a/src/set_elem.c
|
|
+++ b/src/set_elem.c
|
|
@@ -732,14 +732,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);
|
|
}
|
|
|
|
--
|
|
2.33.0
|
|
|