jsonrpc: make sure even errors are valid json.

We often quote their msg in our reply; sanitize it!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-12-03 09:30:39 +10:30
committed by Christian Decker
parent 164c76454c
commit aee2197a66
2 changed files with 12 additions and 2 deletions

View File

@@ -480,13 +480,13 @@ struct json_stream *json_stream_fail_nodata(struct command *cmd,
const char *errmsg)
{
struct json_stream *r = json_start(cmd);
struct json_escaped *e = json_partial_escape(tmpctx, errmsg);
assert(code);
assert(errmsg);
json_stream_append_fmt(r, " \"error\" : "
"{ \"code\" : %d,"
" \"message\" : \"%s\"", code, errmsg);
" \"message\" : \"%s\"", code, e->s);
return r;
}