From patchwork Fri Feb 12 20:35:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harmandeep Kaur X-Patchwork-Id: 8297201 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 CBFC49F1C5 for ; Fri, 12 Feb 2016 20:38:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E135820445 for ; Fri, 12 Feb 2016 20:38:47 +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 096CB20444 for ; Fri, 12 Feb 2016 20:38:47 +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 1aUKRa-0003uv-LV; Fri, 12 Feb 2016 20:35:58 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aUKRY-0003uq-F5 for xen-devel@lists.xenproject.org; Fri, 12 Feb 2016 20:35:56 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id A3/4B-13487-B224EB65; Fri, 12 Feb 2016 20:35:55 +0000 X-Env-Sender: write.harmandeep@gmail.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1455309353!9774938!1 X-Originating-IP: [209.85.220.66] 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 52633 invoked from network); 12 Feb 2016 20:35:54 -0000 Received: from mail-pa0-f66.google.com (HELO mail-pa0-f66.google.com) (209.85.220.66) by server-11.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Feb 2016 20:35:54 -0000 Received: by mail-pa0-f66.google.com with SMTP id fl4so4217204pad.2 for ; Fri, 12 Feb 2016 12:35:54 -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=u6TJlmcH2GGWYIDHARmG4kUuY8kFfF5RbtalG6QnEpo=; b=Z2K5M42uYg9U3CAor+RokP+dPNaWShpSk9Rl0OzXwvYMQ89gDLj0X/YaA3+PJUTYKL mfx7ewksnHSQy4BHJwd+TINjlnIp8kyatIUmKukNoYcJKIPKCRafcno1brzGg4lTTyRV vE7u7MoRq39reu8rnLlUOhrc/7wy/YYoLNJ94Cb4QSn4LGmSAcEOg7oJXbMSB6649Wpa pZpheAH0TMwGdOaGnnCh3/XS9SUULPNZA3Jb81NqJk3Wz43jPNCjMHtFMuieVAO51I/s A9jCNmbmHhaF7fveTApStIG8NwBJ7PYyr/seTROtT0EA/9gGw4e/jQrATTScnxkxQ1bz qMSw== 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=u6TJlmcH2GGWYIDHARmG4kUuY8kFfF5RbtalG6QnEpo=; b=NvOKqVLrX/dv8QlzDxGsHAXzbOEuYi5+0czFS+P/L34miah7yMoO4niQAeBymen/rl n0R8onswExYhktsQBlmXY6mF4Bav0zIQsHqaXtHewvyqh8LPdr8RwktrnLo8pntMLldT 8vplwJI1eSopOYUpd20QY11Xi1TmgPW/NwAbmikIDOTeA1a+xFiITS6jI5cechMwlzL3 w97tlTlD/wN8+PaiD/ES6OWY91y8sRGMmDjx9qE24oj1vb6Utxy9GHVvSOOHkEEayTVq 9wFPrHjJGtf7gNlJ1MwEcHoVHkgjLc/ngY7W1DAmQ4LStiMHmqkidT1avLFaRMct3tGz s5Kw== X-Gm-Message-State: AG10YOThj0LTDgVJ6kbu/WZQtXV1jEFLwiedQ9eNkapjk22Eq40Zl2moexPkcww2Xa36zg== X-Received: by 10.66.220.104 with SMTP id pv8mr4967359pac.140.1455309353251; Fri, 12 Feb 2016 12:35:53 -0800 (PST) Received: from localhost.localdomain ([124.253.93.110]) by smtp.googlemail.com with ESMTPSA id s90sm21370548pfa.49.2016.02.12.12.35.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Feb 2016 12:35:52 -0800 (PST) From: Harmandeep Kaur To: xen-devel@lists.xenproject.org Date: Sat, 13 Feb 2016 02:05:13 +0530 Message-Id: <1455309313-5149-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 v3] 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(). Group all calls to xc_version() , so that data copies in various info fields only if all calls to xc_version go error-free. Coverity ID 1351217 Signed-off-by: Harmandeep Kaur --- v2: Change local variable rc to r. Remove xen_version. Better readiblity of blocks of code. v3: Group all calls to xc_version() , so that data copies in various info fields only if all calls to xc_version work. --- tools/libxl/libxl.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 2d18b8d..f660280 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -5267,42 +5267,44 @@ 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; - - xc_version(ctx->xch, XENVER_extraversion, &u.xen_extra); + r = xc_version(ctx->xch, XENVER_version, NULL); + if (r < 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 = r >> 16; + info->xen_version_minor = r & 0xFF; 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,