Fix ASCII character range check for UTF-8

JSON specifies that ASCII control characters 0x00 through 0x1F must
not appear in the string.  This patch adds the lower bounds in order
to handle UTF-8 characters whose individual bytes might be negative
(like the "registered" symbol 0xc2 0xae).

Co-authored-by: Dave Mulford <dave.mulford@gmail.com>
This commit is contained in:
James W. Mills 2026-03-01 09:52:20 -06:00
parent b096704c0d
commit 6eb34c5066

View file

@ -150,7 +150,7 @@ static const char* parse_string(const char *str, pa_json_object *obj) {
if (*str != '\\') { if (*str != '\\') {
/* JSON specifies that ASCII control characters 0x00 through 0x1F /* JSON specifies that ASCII control characters 0x00 through 0x1F
* must not appear in the string. */ * must not appear in the string. */
if (*str < 0x20) { if (*str >= 0x00 && *str < 0x20) {
pa_log("Invalid ASCII character: 0x%x", (unsigned int) *str); pa_log("Invalid ASCII character: 0x%x", (unsigned int) *str);
goto error; goto error;
} }
@ -763,7 +763,7 @@ static char *pa_json_escape(const char *p) {
*output++ = 't'; *output++ = 't';
break; break;
default: default:
if (*s < 0x20 || *s == 0x7F) { if ((*s >= 0x00 && *s < 0x20) || *s == 0x7F) {
pa_log("Invalid ASCII character: 0x%x", (unsigned int) *s); pa_log("Invalid ASCII character: 0x%x", (unsigned int) *s);
pa_xfree(out_string); pa_xfree(out_string);
return NULL; return NULL;