From patchwork Wed Mar 2 20:09:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harmandeep Kaur X-Patchwork-Id: 8485161 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 00F089F2F0 for ; Wed, 2 Mar 2016 20:12:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0573120383 for ; Wed, 2 Mar 2016 20:12:33 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F1D7120382 for ; Wed, 2 Mar 2016 20:12:31 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1abD5b-0002zr-LF; Wed, 02 Mar 2016 20:09:43 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1abD5b-0002zk-5r for xen-devel@lists.xenproject.org; Wed, 02 Mar 2016 20:09:43 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id 74/F6-30003-68847D65; Wed, 02 Mar 2016 20:09:42 +0000 X-Env-Sender: write.harmandeep@gmail.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1456949380!26421530!1 X-Originating-IP: [209.85.192.196] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46440 invoked from network); 2 Mar 2016 20:09:41 -0000 Received: from mail-pf0-f196.google.com (HELO mail-pf0-f196.google.com) (209.85.192.196) by server-9.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 2 Mar 2016 20:09:41 -0000 Received: by mail-pf0-f196.google.com with SMTP id 184so1990pff.1 for ; Wed, 02 Mar 2016 12:09:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=klzhjJlhYlv36SZLDJtKa8bXvSoTYqFm7YqVFNacN4g=; b=JL5T2VsKGVb+vgYLIxzIlTdvB8e/As2K/ID2uX1l05wgdwiRAuRxdSAJE4qxgmwguO gXg1zwFUgblm2GkruEtRnnHIG6YWCg05sBdml55R+vqSc5rl+AHJKEqqiwPbnMJvDqwv JJyKasnUJCj6c2PcyLvz/zUb8+kBUXW+a9sgtheEOp5qjGZHljEAoqHb7BAqkq4I4F3r dcpG2UyDjeTWGCwXd1M4WIi/SUvmUhcscx8YfA2ByxtxgtLL8aQE7NWWvzEBVVE41fz/ mWaOcmhZZfnFWehjn6B9oubx5+02z5xcogt1ysXXZYiAQ91Z3ipfAPF7i8bR5vkxIDsi Rpww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=klzhjJlhYlv36SZLDJtKa8bXvSoTYqFm7YqVFNacN4g=; b=FEM03jNuWLI+80+lfFVFXQjmGv+UyG5c8CCJBgoXkaSqPjkpk1GLzTPEbqyRZSBxGO Fi4LqxjO05YiNZ57N4q1DvkTfoUb8yDt7H00q3PSFK0GGxW5aEXFDEUJkIdKeREaXmSO TO1dun2OffL/B5Vfgh3NMFummtO5cbpAPnpw6AYraor7noYQc/PNSxV8GXMuNGmyuxgZ LirQABEQBTAozQOwWxKe0KTajmVpIsGJ8D7qQVQBmZJoMh77979whUW8WLwvXyVRc8x/ 8yUtapjBZhda+ELa0IGrSDywiNiX0yMH7vPII4nWlXvH9ChurbU/PJulL4SHSAWyITv0 IgWQ== X-Gm-Message-State: AD7BkJKS7mhhfTlWfRJIQ8fme38cCRDDoiestK037dGZwBMBvNO7TnuFFLFxCU+2H2AH/Q== X-Received: by 10.98.14.67 with SMTP id w64mr41733369pfi.154.1456949380147; Wed, 02 Mar 2016 12:09:40 -0800 (PST) Received: from localhost.localdomain ([124.253.86.158]) by smtp.googlemail.com with ESMTPSA id i13sm54891093pfi.95.2016.03.02.12.09.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Mar 2016 12:09:39 -0800 (PST) From: Harmandeep Kaur To: xen-devel@lists.xenproject.org Date: Thu, 3 Mar 2016 01:39:24 +0530 Message-Id: <1456949364-2527-1-git-send-email-write.harmandeep@gmail.com> X-Mailer: git-send-email 2.5.0 Cc: wei.liu2@citrix.com, ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, dario.faggioli@citrix.com, ian.jackson@eu.citrix.com, Harmandeep Kaur Subject: [Xen-devel] [PATCH v5] libxl: handle failure of xc_version() in libxl_get_version_info() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check the return value of xc_version() and return NULL if it fails. libxl_get_version_info() can also return NULL now. Group all calls to xc_version() , so that data copies in various info fields only if all calls to xc_version work. This will eliminate cases in which only partial information is updated. Callers of the function libxl_get_version_info() are already prepared to deal with a NULL return value. Coverity ID 1351217 Signed-off-by: Harmandeep Kaur Reviewed-by: Dario Faggioli --- v2: Change local variable rc to r. Removes xen_version. Better readiblity of blocks of code. Group all calls to xc_version() , so that data copies in various info fields only if all calls to xc_version go error-free. v3: Group all calls to xc_version() , so that data copies in various info fields only if all calls to xc_version work. v4: Improve suboptimal subject. Readds xen_version to suit re-arrangement. v5: Change datatype of 'r' from long to int. --- tools/libxl/libxl.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 4cdc169..d7bc836 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -5203,41 +5203,44 @@ const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx) xen_commandline_t xen_commandline; } u; long xen_version; + int r = 0; libxl_version_info *info = &ctx->version_info; if (info->xen_version_extra != NULL) goto out; xen_version = xc_version(ctx->xch, XENVER_version, NULL); + if (xen_version < 0) goto out; + r = xc_version(ctx->xch, XENVER_extraversion, &u.xen_extra); + if (r < 0) goto out; + r = xc_version(ctx->xch, XENVER_compile_info, &u.xen_cc); + if (r < 0) goto out; + r = xc_version(ctx->xch, XENVER_capabilities, &u.xen_caps); + if (r < 0) goto out; + r = xc_version(ctx->xch, XENVER_changeset, &u.xen_chgset); + if (r < 0) goto out; + r = xc_version(ctx->xch, XENVER_platform_parameters, &u.p_parms); + if (r < 0) goto out; + r = info->pagesize = xc_version(ctx->xch, XENVER_pagesize, NULL); + if (r < 0) goto out; + r = xc_version(ctx->xch, XENVER_commandline, &u.xen_commandline); + if (r < 0) goto out; + info->xen_version_major = xen_version >> 16; info->xen_version_minor = xen_version & 0xFF; - - xc_version(ctx->xch, XENVER_extraversion, &u.xen_extra); info->xen_version_extra = libxl__strdup(NOGC, u.xen_extra); - - xc_version(ctx->xch, XENVER_compile_info, &u.xen_cc); info->compiler = libxl__strdup(NOGC, u.xen_cc.compiler); info->compile_by = libxl__strdup(NOGC, u.xen_cc.compile_by); info->compile_domain = libxl__strdup(NOGC, u.xen_cc.compile_domain); info->compile_date = libxl__strdup(NOGC, u.xen_cc.compile_date); - - xc_version(ctx->xch, XENVER_capabilities, &u.xen_caps); info->capabilities = libxl__strdup(NOGC, u.xen_caps); - - xc_version(ctx->xch, XENVER_changeset, &u.xen_chgset); info->changeset = libxl__strdup(NOGC, u.xen_chgset); - - xc_version(ctx->xch, XENVER_platform_parameters, &u.p_parms); info->virt_start = u.p_parms.virt_start; - - info->pagesize = xc_version(ctx->xch, XENVER_pagesize, NULL); - - xc_version(ctx->xch, XENVER_commandline, &u.xen_commandline); info->commandline = libxl__strdup(NOGC, u.xen_commandline); out: GC_FREE; - return info; + return r < 0 ? NULL : info; } libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,