diff options
author | Anthony PERARD <anthony.perard@citrix.com> | 2011-11-04 12:38:22 +0000 |
---|---|---|
committer | Anthony PERARD <anthony.perard@citrix.com> | 2011-11-04 12:38:22 +0000 |
commit | a3671a3ba79aa8e952881ecdaf6dd5767cc7b094 (patch) | |
tree | 1dc3b590e0e824d15d7e273525bdfc081caf3708 /tools/libxl/libxl_json.c | |
parent | 4b9b9734bea7d266c9005cb548e4cfd4541001af (diff) | |
download | xen-a3671a3ba79aa8e952881ecdaf6dd5767cc7b094.tar.gz xen-a3671a3ba79aa8e952881ecdaf6dd5767cc7b094.tar.bz2 xen-a3671a3ba79aa8e952881ecdaf6dd5767cc7b094.zip |
libxl: libxl_json: Check the parser status before to call parse_complete
Also, use goto to handle an error.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
Diffstat (limited to 'tools/libxl/libxl_json.c')
-rw-r--r-- | tools/libxl/libxl_json.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/tools/libxl/libxl_json.c b/tools/libxl/libxl_json.c index 11f65fc334..389b697324 100644 --- a/tools/libxl/libxl_json.c +++ b/tools/libxl/libxl_json.c @@ -730,6 +730,8 @@ libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s) { yajl_status status; libxl__yajl_ctx yajl_ctx; + libxl__json_object *o = NULL; + unsigned char *str = NULL; memset(&yajl_ctx, 0, sizeof (yajl_ctx)); yajl_ctx.gc = gc; @@ -744,30 +746,31 @@ libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s) yajl_ctx.hand = yajl_alloc(&callbacks, &cfg, NULL, &yajl_ctx); } status = yajl_parse(yajl_ctx.hand, (const unsigned char *)s, strlen(s)); + if (status != yajl_status_ok) + goto out; + status = yajl_parse_complete(yajl_ctx.hand); + if (status != yajl_status_ok) + goto out; - if (status == yajl_status_ok) { - libxl__json_object *o = yajl_ctx.head; + o = yajl_ctx.head; - DEBUG_GEN_REPORT(&yajl_ctx); + DEBUG_GEN_REPORT(&yajl_ctx); - yajl_ctx.head = NULL; + yajl_ctx.head = NULL; - yajl_ctx_free(&yajl_ctx); - return o; - } else { - unsigned char *str = yajl_get_error(yajl_ctx.hand, 1, - (const unsigned char *)s, - strlen(s)); + yajl_ctx_free(&yajl_ctx); + return o; - LIBXL__LOG(libxl__gc_owner(gc), LIBXL__LOG_ERROR, - "yajl error: %s", str); - yajl_free_error(yajl_ctx.hand, str); +out: + str = yajl_get_error(yajl_ctx.hand, 1, (const unsigned char*)s, strlen(s)); - libxl__json_object_free(gc, yajl_ctx.head); - yajl_ctx_free(&yajl_ctx); - return NULL; - } + LIBXL__LOG(libxl__gc_owner(gc), LIBXL__LOG_ERROR, "yajl error: %s", str); + yajl_free_error(yajl_ctx.hand, str); + + libxl__json_object_free(gc, yajl_ctx.head); + yajl_ctx_free(&yajl_ctx); + return NULL; } static const char *yajl_gen_status_to_string(yajl_gen_status s) |