From a5b21f30c480474bc7e3afa6cbd888752b71aba9 Mon Sep 17 00:00:00 2001 From: Coleman Kane Date: Thu, 19 Oct 2017 10:06:31 -0400 Subject: [PATCH] Fix JSON graph output when opcode has quotes (#8712) When the opcode entity has quotation marks in it, the old code wouldn't escape them, causing unparseable JSON output. This fixes that, in a manner similar to other JSON handling in the project. --- libr/core/disasm.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libr/core/disasm.c b/libr/core/disasm.c index b5d9b9bd7c..a054c1d5d8 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -4330,9 +4330,19 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte } r_cons_printf (",\"size\":%d", ds->analop.size); { + char *quoted_str, *qpos, *spos = NULL; char *escaped_str = r_str_utf16_encode (str, -1); - r_cons_printf (",\"opcode\":\"%s\"", escaped_str); + qpos = quoted_str = malloc (strlen (escaped_str)*4 + 1); + for(spos = escaped_str; *spos != '\0'; spos++) { + if(*spos == '"') { + *qpos++ = '\\'; + } + *qpos++ = *spos; + } + *qpos = '\0'; + r_cons_printf (",\"opcode\":\"%s\"", quoted_str); free (escaped_str); + free (quoted_str); } r_cons_printf (",\"bytes\":\"%s\"", asmop.buf_hex); r_cons_printf (",\"family\":\"%s\"",