From patchwork Fri Feb 12 11:30:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harmandeep Kaur X-Patchwork-Id: 8290321 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 80F39BEEE5 for ; Fri, 12 Feb 2016 11:34:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8F778203C0 for ; Fri, 12 Feb 2016 11:34:02 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9A8AD20397 for ; Fri, 12 Feb 2016 11:34:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aUBwe-00020T-V3; Fri, 12 Feb 2016 11:31:28 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aUBwd-00020O-Fq for xen-devel@lists.xenproject.org; Fri, 12 Feb 2016 11:31:27 +0000 Received: from [193.109.254.147] by server-1.bemta-14.messagelabs.com id A9/99-28791-E82CDB65; Fri, 12 Feb 2016 11:31:26 +0000 X-Env-Sender: write.harmandeep@gmail.com X-Msg-Ref: server-13.tower-27.messagelabs.com!1455276684!23328364!1 X-Originating-IP: [209.85.220.68] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34233 invoked from network); 12 Feb 2016 11:31:25 -0000 Received: from mail-pa0-f68.google.com (HELO mail-pa0-f68.google.com) (209.85.220.68) by server-13.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Feb 2016 11:31:25 -0000 Received: by mail-pa0-f68.google.com with SMTP id zv9so1323504pab.3 for ; Fri, 12 Feb 2016 03:31:25 -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=FkCoe3bLh7b08US2OAZs3oY65tvXCgpUXiLnIXBSNBc=; b=sx7/UXdJWbiSy9paFfx8BWNInZ/+1DeygGTomaGiiiaedzGl8zr+AK6XVi1yyCU8Wh xigphqVc0LarCzbSbFjA9J8bCY4xTT4qFAhcuB8dRtn44IoNTSYfH3YuoQSq2Ds2+SBi EGE744BhgD0NWQbXJvswKVNPFM/24O+QzfF0PbGVfU6NsgFF9QzbOPRULvbKSVk8rOI/ 8YOQjg/niIUuRW/qOBNj6XwDaAVQTBXAexAUIbHb9bzYL9Oc1MFDJOqI72/KLKR9dEO+ zrlHkiobN2a/z32M/PaU6xnmjCHhJjZdUtzKEjrjsVyx4pU6lWsJ1odgdtmRcCCQODC+ M8Mw== 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=FkCoe3bLh7b08US2OAZs3oY65tvXCgpUXiLnIXBSNBc=; b=d/Sh2x5Ag4HT7tGBZsuq2g2aXccc5HTL7EYChXI7EHKiSIY9+91byeOy+44xLq3O9F LGpu7U1sYIC3E7hoBwWRhihzv22kTnm+BeQ2b/1VOUm6GdWaJZTyWf4a19twpvaDpIe6 RC2VFN6jiAnTDVhZs3azTJC0NYJC3Ez7QWr9IQd1DyLLtHQC3l5LCyfUpYgwl+zdlYN1 C8pK335hd4Jx/Q+X5AM8IcZNXrLlWJmEiYVn7b5EvzkzDCf48Tx+z0tKKcyFr8KxUBXF dBUh5jIm51aiCuNVhe2LZhiEfYYxwfOY3+34Lj7cvkRzHDDwnvjD3hirtVLB8boYfuZo Grpw== X-Gm-Message-State: AG10YOTaMQdtAhLlZf7qiv+jy709evdM2egUwwp2MF/zcFmL14RvLzu3JKo+jfxYOBjKNw== X-Received: by 10.67.8.2 with SMTP id dg2mr1411568pad.30.1455276684032; Fri, 12 Feb 2016 03:31:24 -0800 (PST) Received: from localhost.localdomain ([124.253.93.110]) by smtp.googlemail.com with ESMTPSA id ey2sm18891441pab.2.2016.02.12.03.31.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Feb 2016 03:31:23 -0800 (PST) From: Harmandeep Kaur To: xen-devel@lists.xenproject.org Date: Fri, 12 Feb 2016 17:00:40 +0530 Message-Id: <1455276640-3735-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 v2] libxl: fix handling of returns in libxl_get_version_info() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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. Callers of the function libxl_get_version_info() are already prepared to deal with returning NULL on failure of xc_version(). Coverity ID 1351217 Signed-off-by: Harmandeep Kaur --- v2: Change local variable rc to r. Remove xen_version. Better readiblity of blocks of code. --- tools/libxl/libxl.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 2d18b8d..771cc40 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -5267,42 +5267,50 @@ const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx) xen_platform_parameters_t p_parms; xen_commandline_t xen_commandline; } u; - long xen_version; + long 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); - info->xen_version_major = xen_version >> 16; - info->xen_version_minor = xen_version & 0xFF; + r = xc_version(ctx->xch, XENVER_version, NULL); + if ( r < 0 ) goto out; + info->xen_version_major = r >> 16; + info->xen_version_minor = r & 0xFF; - xc_version(ctx->xch, XENVER_extraversion, &u.xen_extra); + r = xc_version(ctx->xch, XENVER_extraversion, &u.xen_extra); + if ( r < 0 ) goto out; info->xen_version_extra = libxl__strdup(NOGC, u.xen_extra); - xc_version(ctx->xch, XENVER_compile_info, &u.xen_cc); + r = xc_version(ctx->xch, XENVER_compile_info, &u.xen_cc); + if ( r < 0 ) goto out; 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); + r = xc_version(ctx->xch, XENVER_capabilities, &u.xen_caps); + if ( r < 0 ) goto out; info->capabilities = libxl__strdup(NOGC, u.xen_caps); - xc_version(ctx->xch, XENVER_changeset, &u.xen_chgset); + r = xc_version(ctx->xch, XENVER_changeset, &u.xen_chgset); + if ( r < 0 ) goto out; info->changeset = libxl__strdup(NOGC, u.xen_chgset); - xc_version(ctx->xch, XENVER_platform_parameters, &u.p_parms); + r = xc_version(ctx->xch, XENVER_platform_parameters, &u.p_parms); + if ( r < 0 ) goto out; info->virt_start = u.p_parms.virt_start; - info->pagesize = xc_version(ctx->xch, XENVER_pagesize, NULL); + r = info->pagesize = xc_version(ctx->xch, XENVER_pagesize, NULL); + if ( r < 0 ) goto out; - xc_version(ctx->xch, XENVER_commandline, &u.xen_commandline); + r = xc_version(ctx->xch, XENVER_commandline, &u.xen_commandline); + if ( r < 0 ) goto out; 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,