diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-02-03 11:49:14 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-02-03 17:04:05 +0100 |
commit | d5003fde57eab19588da7bfdbaefe93d47435eb6 (patch) | |
tree | eab61f9e563bb78f2648f9a0bdb11c672342fd25 /lib.c | |
parent | 5d0ecd9aefee1be2b51713f7343939b7039a0406 (diff) |
lib: fix leaking tokener in uc_json() on parse exception
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -2048,10 +2048,10 @@ uc_replace(uc_vm_t *vm, size_t nargs) static uc_value_t * uc_json(uc_vm_t *vm, size_t nargs) { - uc_value_t *rv, *src = uc_fn_arg(0); + uc_value_t *rv = NULL, *src = uc_fn_arg(0); struct json_tokener *tok = NULL; enum json_tokener_error err; - json_object *jso; + json_object *jso = NULL; const char *str; size_t len; @@ -2073,32 +2073,30 @@ uc_json(uc_vm_t *vm, size_t nargs) err = json_tokener_get_error(tok); if (err == json_tokener_continue) { - json_object_put(jso); uc_vm_raise_exception(vm, EXCEPTION_SYNTAX, "Unexpected end of string in JSON data"); - return NULL; + goto out; } else if (err != json_tokener_success) { - json_object_put(jso); uc_vm_raise_exception(vm, EXCEPTION_SYNTAX, "Failed to parse JSON string: %s", json_tokener_error_desc(err)); - return NULL; + goto out; } else if (json_tokener_get_parse_end(tok) < len) { - json_object_put(jso); uc_vm_raise_exception(vm, EXCEPTION_SYNTAX, "Trailing garbage after JSON data"); - return NULL; + goto out; } - json_tokener_free(tok); rv = ucv_from_json(vm, jso); +out: + json_tokener_free(tok); json_object_put(jso); return rv; |