From nobody Fri May 3 14:09:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1591077659; cv=none; d=zohomail.com; s=zohoarc; b=FnUHqLO0PqicnAsgx+HDB77k1XJFNRXdko2WEkBPkcpljAA3Kmo+WE9l/IP0tZTD4ZB1P0jGohjecBjj82UZ43SdJlywI7aaMh4bxqtCGudM03pm/tYD1Kn+5pbTxfSB3VNUhGn2iP02FBZWBLbxPL8Cg6bn7PEdUeHwJQeIQr4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591077659; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1r96BlONSLK8P+auANpuGCu7STu6PAa3FSTSdZMR3qU=; b=eVPTddlxDjKxT/Xu5e1GGclhD2cNvLlZHjyUY7vf/yYDk4JSR4MnbUYb1PjafA3YblWOwqELfjkr5ECUq3YWN5LC+ioKwsRyvzPCDf8E3nsT89avIPbLNGfXQhtav2lHDsZuuL1UFc9FfXvfRd5HnmYTivNTtQdiEI7wMq0bF7U= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1591077659574891.926893668352; Mon, 1 Jun 2020 23:00:59 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jfzyN-0002nm-5p; Tue, 02 Jun 2020 06:00:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jfzyL-0002nh-Ll for xen-devel@lists.xenproject.org; Tue, 02 Jun 2020 06:00:25 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 599ed8f8-a496-11ea-8993-bc764e2007e4; Tue, 02 Jun 2020 06:00:24 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 09BD5AFA7; Tue, 2 Jun 2020 06:00:25 +0000 (UTC) X-Inumbo-ID: 599ed8f8-a496-11ea-8993-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Subject: [PATCH-for-4.14 1/2] tools: check return value of asprintf() in xenhypfs Date: Tue, 2 Jun 2020 08:00:20 +0200 Message-Id: <20200602060021.23289-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602060021.23289-1-jgross@suse.com> References: <20200602060021.23289-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Andrew Cooper , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" asprintf() can fail, so check its return value. Additionally fix a memory leak in xenhypfs. Reported-by: Andrew Cooper Signed-off-by: Juergen Gross Acked-by: Wei Liu --- tools/misc/xenhypfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/misc/xenhypfs.c b/tools/misc/xenhypfs.c index 158b901f42..5145b8969f 100644 --- a/tools/misc/xenhypfs.c +++ b/tools/misc/xenhypfs.c @@ -148,9 +148,14 @@ static int xenhypfs_tree_sub(char *path, unsigned int = depth) printf("%*s%s%s\n", depth * 2, "", ent[i].name, ent[i].type =3D=3D xenhypfs_type_dir ? "/" : ""); if (ent[i].type =3D=3D xenhypfs_type_dir) { - asprintf(&p, "%s%s%s", path, (depth =3D=3D 1) ? "" : "/", ent[= i].name); + if (asprintf(&p, "%s%s%s", path, (depth =3D=3D 1) ? "" : "/", + ent[i].name) < 0) { + ret =3D 2; + break; + } if (xenhypfs_tree_sub(p, depth + 1)) ret =3D 2; + free(p); } } =20 --=20 2.26.2 From nobody Fri May 3 14:09:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1591077658; cv=none; d=zohomail.com; s=zohoarc; b=BWQ1YEwLa3kIqenjkUfNd5NwHG07HGKiop0YOwFskkI6CcM1AdASZiKGYLUEtnN7pzPFUDkqLhlfhhJzXyBrwgCDPxcmlC74NAdoNZzIz7dMj2oGYSw0tJq+nTKbkGhvmJOxbUWMa4fP+SBKm//+J7Ad+l5sOa1Ia7Yy+kcOxkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591077658; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FG+gjWhJ1ntY1EbUX3rxKKPvlUa0qipcuMDZ74WdpcE=; b=e6fEuJgDykc7A8W4wObNAS5aIqMU4JgnqcP0sM6LjO8ObPmJkteIh73zMqboRBrBmBbfg92fA7N1dwbRaiL9CEjompF1rPGBZUogNJ7Xg9EnrBhy0T/LK5I+PgyWiUCQT1oHkI8ZmMVtF/fOHS7Wec6h174qVMGbZV9W12qU0Uk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 159107765842729.770200422588232; Mon, 1 Jun 2020 23:00:58 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jfzyP-0002nx-E2; Tue, 02 Jun 2020 06:00:29 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jfzyO-0002ns-HM for xen-devel@lists.xenproject.org; Tue, 02 Jun 2020 06:00:28 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 59a040db-a496-11ea-ab98-12813bfff9fa; Tue, 02 Jun 2020 06:00:25 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 252CDAFB0; Tue, 2 Jun 2020 06:00:26 +0000 (UTC) X-Inumbo-ID: 59a040db-a496-11ea-ab98-12813bfff9fa X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Subject: [PATCH-for-4.14 2/2] tools: make libxenhypfs interface more future proof Date: Tue, 2 Jun 2020 08:00:21 +0200 Message-Id: <20200602060021.23289-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602060021.23289-1-jgross@suse.com> References: <20200602060021.23289-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Andrew Cooper , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" As compilers are free to choose the width of an enum they should be avoided in stable interfaces when declaring a variable. So the struct xenhypfs_dirent definition should be modified to have explicitly sized members for type and encoding and the related enums should be defined separately. Additionally it is better to have a larger flags member in that struct with the "writable" indicator occupying only a single bit. This will make future additions easier. Suggested-by: Andrew Cooper Signed-off-by: Juergen Gross Acked-by: Wei Liu --- tools/libs/hypfs/core.c | 2 +- tools/libs/hypfs/include/xenhypfs.h | 31 +++++++++++++++++------------ tools/misc/xenhypfs.c | 3 ++- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/tools/libs/hypfs/core.c b/tools/libs/hypfs/core.c index d4309b5ae2..c91e165705 100644 --- a/tools/libs/hypfs/core.c +++ b/tools/libs/hypfs/core.c @@ -204,7 +204,7 @@ static void xenhypfs_set_attrs(struct xen_hypfs_direntr= y *entry, dirent->type =3D xenhypfs_type_blob; } =20 - dirent->is_writable =3D entry->max_write_len; + dirent->flags =3D entry->max_write_len ? XENHYPFS_FLAG_WRITABLE : 0; } =20 void *xenhypfs_read_raw(xenhypfs_handle *fshdl, const char *path, diff --git a/tools/libs/hypfs/include/xenhypfs.h b/tools/libs/hypfs/include= /xenhypfs.h index ab157edceb..25432d2a16 100644 --- a/tools/libs/hypfs/include/xenhypfs.h +++ b/tools/libs/hypfs/include/xenhypfs.h @@ -26,22 +26,27 @@ struct xentoollog_logger; =20 typedef struct xenhypfs_handle xenhypfs_handle; =20 +enum xenhypfs_type { + xenhypfs_type_dir, + xenhypfs_type_blob, + xenhypfs_type_string, + xenhypfs_type_uint, + xenhypfs_type_int, + xenhypfs_type_bool, +}; + +enum xenhypfs_encoding { + xenhypfs_enc_plain, + xenhypfs_enc_gzip +}; + struct xenhypfs_dirent { char *name; size_t size; - enum { - xenhypfs_type_dir, - xenhypfs_type_blob, - xenhypfs_type_string, - xenhypfs_type_uint, - xenhypfs_type_int, - xenhypfs_type_bool - } type; - enum { - xenhypfs_enc_plain, - xenhypfs_enc_gzip - } encoding; - bool is_writable; + unsigned short type; + unsigned short encoding; + unsigned int flags; +#define XENHYPFS_FLAG_WRITABLE 0x00000001 }; =20 xenhypfs_handle *xenhypfs_open(struct xentoollog_logger *logger, diff --git a/tools/misc/xenhypfs.c b/tools/misc/xenhypfs.c index 5145b8969f..5da24aed90 100644 --- a/tools/misc/xenhypfs.c +++ b/tools/misc/xenhypfs.c @@ -125,7 +125,8 @@ static int xenhypfs_ls(char *path) } else { for (i =3D 0; i < n; i++) printf("%s r%c %s\n", xenhypfs_type(ent + i), - ent[i].is_writable ? 'w' : '-', ent[i].name); + (ent[i].flags & XENHYPFS_FLAG_WRITABLE) ? 'w' : '-', + ent[i].name); =20 free(ent); } --=20 2.26.2