* [PATCH iproute 1/2] json_writer: support control character escaping @ 2026-04-10 22:47 Stephen Hemminger 2026-04-10 22:47 ` [PATCH iproute 2/2] json_writer: fix builtin test code Stephen Hemminger 2026-04-13 19:10 ` [PATCH iproute 1/2] json_writer: support control character escaping patchwork-bot+netdevbpf 0 siblings, 2 replies; 3+ messages in thread From: Stephen Hemminger @ 2026-04-10 22:47 UTC (permalink / raw) To: netdev; +Cc: Stephen Hemminger Iproute2 never handled control characters in strings correctly. There are some cases like where string is under user control like paths in ss command. Make iproute2 json output conform to RFC 8259. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- lib/json_writer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/json_writer.c b/lib/json_writer.c index 2f3936c2..7202621e 100644 --- a/lib/json_writer.c +++ b/lib/json_writer.c @@ -53,7 +53,7 @@ static void jsonw_eor(json_writer_t *self) /* Output JSON encoded string */ -/* Handles C escapes, does not do Unicode */ +/* Handles C escapes and control characters per RFC 8259 */ static void jsonw_puts(json_writer_t *self, const char *str) { putc('"', self->out); @@ -81,7 +81,10 @@ static void jsonw_puts(json_writer_t *self, const char *str) fputs("\\\"", self->out); break; default: - putc(*str, self->out); + if ((unsigned char)*str < 0x20 || *str == 0x7f) + fprintf(self->out, "\\u%04x", *str); + else + putc(*str, self->out); } putc('"', self->out); } -- 2.53.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH iproute 2/2] json_writer: fix builtin test code 2026-04-10 22:47 [PATCH iproute 1/2] json_writer: support control character escaping Stephen Hemminger @ 2026-04-10 22:47 ` Stephen Hemminger 2026-04-13 19:10 ` [PATCH iproute 1/2] json_writer: support control character escaping patchwork-bot+netdevbpf 1 sibling, 0 replies; 3+ messages in thread From: Stephen Hemminger @ 2026-04-10 22:47 UTC (permalink / raw) To: netdev; +Cc: Stephen Hemminger The code under #ifdef was not generating valid JSON and it is missing test for control characters. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- lib/json_writer.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/json_writer.c b/lib/json_writer.c index 7202621e..d4a1c72b 100644 --- a/lib/json_writer.c +++ b/lib/json_writer.c @@ -369,7 +369,7 @@ int main(int argc, char **argv) jsonw_null_field(wr, "my_null"); jsonw_name(wr, "special chars"); - jsonw_start_array(wr); + jsonw_start_object(wr); jsonw_string_field(wr, "slash", "/"); jsonw_string_field(wr, "newline", "\n"); jsonw_string_field(wr, "tab", "\t"); @@ -377,7 +377,14 @@ int main(int argc, char **argv) jsonw_string_field(wr, "quote", "\""); jsonw_string_field(wr, "tick", "\'"); jsonw_string_field(wr, "backslash", "\\"); - jsonw_end_array(wr); + jsonw_end_object(wr); + + jsonw_name(wr, "control chars"); + jsonw_start_object(wr); + jsonw_string_field(wr, "bell", "\a"); + jsonw_string_field(wr, "esc", "\033"); + jsonw_string_field(wr, "del", "\177"); + jsonw_end_object(wr); jsonw_end_object(wr); -- 2.53.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute 1/2] json_writer: support control character escaping 2026-04-10 22:47 [PATCH iproute 1/2] json_writer: support control character escaping Stephen Hemminger 2026-04-10 22:47 ` [PATCH iproute 2/2] json_writer: fix builtin test code Stephen Hemminger @ 2026-04-13 19:10 ` patchwork-bot+netdevbpf 1 sibling, 0 replies; 3+ messages in thread From: patchwork-bot+netdevbpf @ 2026-04-13 19:10 UTC (permalink / raw) To: Stephen Hemminger; +Cc: netdev Hello: This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <stephen@networkplumber.org>: On Fri, 10 Apr 2026 15:47:44 -0700 you wrote: > Iproute2 never handled control characters in strings correctly. > There are some cases like where string is under user control > like paths in ss command. Make iproute2 json output conform > to RFC 8259. > > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> > > [...] Here is the summary with links: - [iproute,1/2] json_writer: support control character escaping https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=9e99260759b7 - [iproute,2/2] json_writer: fix builtin test code https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=fe811be6564c You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-13 19:10 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-10 22:47 [PATCH iproute 1/2] json_writer: support control character escaping Stephen Hemminger 2026-04-10 22:47 ` [PATCH iproute 2/2] json_writer: fix builtin test code Stephen Hemminger 2026-04-13 19:10 ` [PATCH iproute 1/2] json_writer: support control character escaping patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox