From patchwork Tue Nov 1 16:07:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 123098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C525BB6F85 for ; Wed, 2 Nov 2011 03:40:20 +1100 (EST) Received: from localhost ([::1]:38458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLGtA-0002KY-7d for incoming@patchwork.ozlabs.org; Tue, 01 Nov 2011 12:08:36 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLGsk-0001DY-5t for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLGsi-0004fU-DW for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:09 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:10465) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLGsi-0004ct-A0 for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:08 -0400 X-IronPort-AV: E=Sophos;i="4.69,438,1315195200"; d="scan'208";a="168952513" Received: from ftlpmailmx02.citrite.net ([10.13.107.66]) by FTLPIPO02.CITRIX.COM with ESMTP/TLS/RC4-MD5; 01 Nov 2011 12:07:52 -0400 Received: from smtp01.ad.xensource.com (10.219.128.104) by smtprelay.citrix.com (10.13.107.66) with Microsoft SMTP Server id 8.3.137.0; Tue, 1 Nov 2011 12:07:52 -0400 Received: from perard.uk.xensource.com (dhcp-3-28.uk.xensource.com [10.80.3.28] (may be forged)) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id pA1G7YNF014577; Tue, 1 Nov 2011 09:07:50 -0700 From: Anthony PERARD To: QEMU-devel , Stefano Stabellini Date: Tue, 1 Nov 2011 16:07:15 +0000 Message-ID: <1320163646-24291-3-git-send-email-anthony.perard@citrix.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1320163646-24291-1-git-send-email-anthony.perard@citrix.com> References: <1320163646-24291-1-git-send-email-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Cc: Anthony PERARD , Xen Devel Subject: [Qemu-devel] [PATCH V3 02/13] libxl_json: Check the parser status before to call parse_complete X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Also, use goto to handle an error. Signed-off-by: Anthony PERARD --- 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 11f65fc..389b697 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)