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>
/* 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);
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);
}