diff options
author | Gary E. Miller <gem@rellim.com> | 2011-01-10 12:45:39 -0800 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2011-01-10 12:45:39 -0800 |
commit | 6abc35579e430c4eebc803f31139cd5654d540ec (patch) | |
tree | 8760e11a21b0554b1e891df4f0fe66f8953f76a1 /gpsd_json.c | |
parent | 8e56d2fdd22d9d5f2c1254183fb5c18bfc3485e2 (diff) | |
download | gpsd-6abc35579e430c4eebc803f31139cd5654d540ec.tar.gz |
Fix JSON to properly escape. Escape subframe system message.
Diffstat (limited to 'gpsd_json.c')
-rw-r--r-- | gpsd_json.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/gpsd_json.c b/gpsd_json.c index 3cde20a4..c5440601 100644 --- a/gpsd_json.c +++ b/gpsd_json.c @@ -85,7 +85,9 @@ char *json_stringify( /*@out@*/ char *to, break; default: /* ugh, we'd prefer a C-style escape here, but this is JSON */ - (void)snprintf(tp, 5, "%u04x", (unsigned int)*sp); + /* http://www.ietf.org/rfc/rfc4627.txt + * section 2.5, escape is \uXXXX */ + (void)snprintf(tp, 5, "\\u%u4x", (unsigned int)*sp); tp += strlen(tp); } } else { @@ -358,6 +360,7 @@ void subframe_json_dump(const struct subframe_t *subframe, bool scaled, /*@out@*/ char buf[], size_t buflen) { size_t len = 0; + char buf1[256]; /* need to verify this is big enough */ (void)snprintf(buf, buflen, "{\"class\":\"SUBFRAME\",\"tSV\":%02u," "\"TOW17\":%u,\"frame\":%u,\"scaled\":%s", @@ -560,12 +563,13 @@ void subframe_json_dump(const struct subframe_t *subframe, bool scaled, break; /*@-charint@*/ case 55: - /* FIXME! JSON is UTF-8. double quote, backslash and + /* JSON is UTF-8. double quote, backslash and * control charactores (U+0000 through U+001F).must be - * escaped. That escaping not done yet */ + * escaped. */ + json_stringify(buf1, sizeof(buf1), subframe->sub4_17.str); (void)snprintf(buf + len, buflen - len, ",\"system_message\":\"%.50s\"", - subframe->sub4_17.str); + buf1); break; case 56: if (scaled) { |