* [PATCH libnftnl] rule, set_elem: fix printing of user data
@ 2022-08-27 17:17 Jeremy Sowden
2022-08-29 7:55 ` Pablo Neira Ayuso
0 siblings, 1 reply; 2+ messages in thread
From: Jeremy Sowden @ 2022-08-27 17:17 UTC (permalink / raw)
To: Netfilter Devel
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>
---
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 0bb1c2a0583c..a1a64bd2837d 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 95009acb17dc..1c8720dc7c57 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -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);
}
--
2.35.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH libnftnl] rule, set_elem: fix printing of user data
2022-08-27 17:17 [PATCH libnftnl] rule, set_elem: fix printing of user data Jeremy Sowden
@ 2022-08-29 7:55 ` Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2022-08-29 7:55 UTC (permalink / raw)
To: Jeremy Sowden; +Cc: Netfilter Devel
On Sat, Aug 27, 2022 at 06:17:17PM +0100, Jeremy Sowden wrote:
> 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 }
Applied, thanks
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-08-29 7:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-27 17:17 [PATCH libnftnl] rule, set_elem: fix printing of user data Jeremy Sowden
2022-08-29 7:55 ` Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.