sanitize_string() emits non-printable bytes as \xNN inside JSON string
values. JSON only allows the escape sequences \" \\ \/ \b \f \n \r \t and
\uXXXX. The latter is the correct option for printing arbitrary character
values.

Fixes: ae1a3d3f0bb7 ("batctl: genl_json: Add generic JSON interface")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 genl_json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/genl_json.c b/genl_json.c
index 917b255..bb32cab 100644
--- a/genl_json.c
+++ b/genl_json.c
@@ -40,7 +40,7 @@ static void sanitize_string(const char *str)
                        putchar('\\');
                        putchar(*c);
                } else if (!isprint(*c)) {
-                       printf("\\x%02x", *c);
+                       printf("\\u%04x", *c);
                } else {
                        putchar(*c);
                }

-- 
2.47.3

Reply via email to