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.
This commit is contained in:
Coleman Kane 2017-10-19 10:06:31 -04:00 committed by radare
parent fbec8ce2c2
commit a5b21f30c4

View File

@ -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\"",