Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1ppOXQ-0002nr-Gn for mharc-grub-devel@gnu.org; Thu, 20 Apr 2023 03:17:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppOXP-0002nL-2P for grub-devel@gnu.org; Thu, 20 Apr 2023 03:17:03 -0400 Received: from mail-he1eur04on2053.outbound.protection.outlook.com ([40.107.7.53] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppOXN-00028Q-6U for grub-devel@gnu.org; Thu, 20 Apr 2023 03:17:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JD4UaRvWa5uNDebOnee/wmbHQfD3kWc0/XSMCPIe5Z/vkSx0DNCgesd61G9uxvwT6EPUsr381bhUUITRNrAFJlputHviFlR1Nyk686MlopjjRSEPF2cj9EV0PjoLuXFDuNk8SnYSdgRVbwmBQTorxQUN6fqMKR4T/jW4lssr50KGRFsavGvPM5Lk3vBnOlCtWicwY+OUsuPv50Z2k+FZqgMjBvUJc2vdUTgx4zO/PMyTlH74X48foTELiCLro6QZtbhydEEKS0IdknkkGfSn3Q8FT1N8S5o9KHW/X85sNUAdjCj2nWqHzAUR/4eTIgpye2MRr9c3pE5qlYDw9KUGqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+5ivi4w/hW3Xv7/v548nxRKxBH2BTy2s77tq8mOA0BE=; b=VB4lTYrob+Jq90RXNJqOS5Z3kkXf0lT5kY2K3qWyxstqAhklpdHmLQlsn7waYQB91mz8PBhuJARguXZ2uKIuoxEjobYbMsI5RZKMbHwWjqhgylkjc5lZ/EL5qfP42zVb92TjELAEFbxiZk9yZQYxE7ETcaaO09J4X8tpolskBf7pUyaJMEw41garROOTNN2IzWiLFfVw5Q/3J93glcCDeN7AHxeB35XrJ3hF/mrjwuBDDfhLitkXYScsBSx19MDLAMp0mGdIORoOSTjkB1IpXh0G2kk7BEllbatdrAToyfYybnuiCpN8btEF17/HCzob6u4YpRZvJLC7XBHAb5COWw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+5ivi4w/hW3Xv7/v548nxRKxBH2BTy2s77tq8mOA0BE=; b=lEBC25yTUSqnwQcIHY+4moSKm3fbRKg1xDCaYlAOQESN0YNY9h559l9enUOV8pGVmPp468HR4Nj+CAwWnhV0b6Ak0rlJcKdITcRg/bWKQ06q5UB/5W0HtxKTJF5aoGjFvrnW6Q7aZFfEFP3mSNha/mGw1ro523ztI9ryTazqcjmwU/kLobN4iYQ9w3ikM8kYg90cXgo0jpt0/vDy9YS5Q3KeCKq2UWfrxVeVckKSLauemLE/V4OhNrt7RClAEYZNuZZA/127KOfLgcy5COMMNKuEZK0AJe0Z8sp2PC3t8la0gw6VtUsNuhv/xS/Psc84draZ56z00fLPY3VxJ0ixxA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from DBBPR04MB6140.eurprd04.prod.outlook.com (2603:10a6:10:c7::18) by PAXPR04MB8094.eurprd04.prod.outlook.com (2603:10a6:102:1c1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22; Thu, 20 Apr 2023 07:16:40 +0000 Received: from DBBPR04MB6140.eurprd04.prod.outlook.com ([fe80::dc0f:b8e1:84c9:2906]) by DBBPR04MB6140.eurprd04.prod.outlook.com ([fe80::dc0f:b8e1:84c9:2906%6]) with mapi id 15.20.6298.045; Thu, 20 Apr 2023 07:16:40 +0000 From: Gary Lin To: The development of GNU GRUB Cc: Hernan Gatta , Daniel Axtens , 'Daniel Kiper ' , shkhisti@microsoft.com, jaskaran.khurana@microsoft.com, christopher.co@microsoft.com, daniel.mihai@microsoft.com, rharwood@redhat.com, jaredz@redhat.com, development@efficientek.com, jejb@linux.ibm.com, mchang@suse.com Subject: [PATCH v4 04/12] libtasn1: changes for grub compatibility Date: Thu, 20 Apr 2023 15:15:40 +0800 Message-Id: <20230420071548.28286-5-glin@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230420071548.28286-1-glin@suse.com> References: <20230420071548.28286-1-glin@suse.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TYCP286CA0163.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:383::10) To DBBPR04MB6140.eurprd04.prod.outlook.com (2603:10a6:10:c7::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DBBPR04MB6140:EE_|PAXPR04MB8094:EE_ X-MS-Office365-Filtering-Correlation-Id: 9861b455-a3a8-4477-34e5-08db416f2fc4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8F3ZRvihoijWSU4JYdhIC1CGcY4ZP9y9Tt6gtRnSahHevJo0rsAiOluNUH+RB9aWIB0cOR3BWsTwkMaxmYjXXQGDTuDhSuhG/As/shOQO47KQO9E+6/FZvd77ZgbdGpt0WhkHCCDIkwxoeKol0fVQ5e8ZE7Vwl9JWtgqiWWSeTmNs7RZzgtiOQMBMjkF/L4Ek9MQqvzsCDHdoKMD10KYlQpV5lW6nFusBF/rEdmjASdi1L2dVGNNgVAwwmdVtgbpbJDKZZWFVrBYhowwPkOFs8gNBgdxeJeRgnohJ4dZVQWAtOmK2H+Uda/vMHsJ8vC0PDEDXL5FNZ03RqUGiEi0P+Da4Yy9csC2OaqlSRxSj4GpjoZwlyVsB1AzQIP4ngHa/enXhS43gy44mXjO4Ba5XV7vOrvWUQVmF8FUmOYrE+d8n3N3i59oT7nAbo3nvU2N5jY0n9PuwCd7fB3TJ8lLWudapAtcz9/R8SzvnzLOY1m2XaqakT+mfN+ujmqrv2cadE4mBPDNh7EfGb564YzSON8D4aZg9VHnN/oASecWjFx4o0epJD5Yx76IbWPIFmWB X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DBBPR04MB6140.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(136003)(39860400002)(366004)(396003)(346002)(376002)(451199021)(6916009)(26005)(6512007)(186003)(4326008)(316002)(6506007)(1076003)(8676002)(8936002)(2906002)(36756003)(86362001)(5660300002)(7416002)(478600001)(54906003)(83380400001)(41300700001)(2616005)(38100700002)(6486002)(66556008)(107886003)(66476007)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?iwOnvBiB1VAVUs4pakNgpQTDkaAcKtbpMYKd8Zh+hrU+qufaBXnMe5EOaFhP?= =?us-ascii?Q?w1aI/Iyh+9AIeDfUmqIXA1BOTVWeuknC8JOtCc7l8h+KdwY5YLsbZZU/m4w9?= =?us-ascii?Q?wAR/YtoSXd+oyEqvu+NkIB1tKcf22UhovY1haPWhKcVXtEWAFoOJVA2e28ar?= =?us-ascii?Q?K94v1+i6sLzDTnC+V18huCS3C0lxowbMa7gJ+YvSxdY4K8vestFcWWzpI8q2?= =?us-ascii?Q?PgkL8wcUHXjkDrqbdxoYkHy2xW0KKB0+YB9BCMQOxE/WfQtOeBK212Eagg11?= =?us-ascii?Q?e5cuiZGHo51ulV2m6qtuzumMy6I/EQFSsWWz8urZIkEHs0fhZW2h8jTl0s2T?= =?us-ascii?Q?cZ37FjHHmSNnV18onfywITPtMpILWLOBjvTmdO/DC8w0anjOk8pQDlFQhKT3?= =?us-ascii?Q?K4ZDTTniao0FotyMsL83yCUw+Vq51tX5VNTspfxBufcFytQUhP0oUosuaJYP?= =?us-ascii?Q?S+Ij3Q0jCKfRWZNXsjnSMil1V68Wuulsi3sCScDgcUtKZIbc0GcnynogjFdB?= =?us-ascii?Q?EemkYqD2OFbFEN4oZeErzkVyIISKIn3DXWpK7NDAEQcQU/Pckn/sDX2JgizU?= =?us-ascii?Q?XAV9XuFkbZ9OND3OPnLl1iGjXD6z6zb+Fj/lAshASi3t+lvdXTBMHbKrUTwV?= =?us-ascii?Q?pDFk7U/sUwFMIsXX9hir17EThtvhWeZk16fwQltwTciNDaErk4MRu1fZF/xY?= =?us-ascii?Q?yvnbg+1CwqSl3zttsFqQHCDzi9xkVhiS7k015wRHTzarI0Zcp+E1kf+8Aa1r?= =?us-ascii?Q?8j7xUUU9cObd6yhESwOTzIePfBnmYb1dykunYZ7FZcTKzsqxeIMz/tOAM7eW?= =?us-ascii?Q?+KIbGm4fWE197z+kUXdsKH1mje+CxqInjOb8sa5/Ukyp7Bw49IM3pFhcnni5?= =?us-ascii?Q?9E0/hWj2iQtrccFdMk6ewVJOvQ/QP4iTCXfbIUQWsqEtgKNPNI5GGGuaCJDD?= =?us-ascii?Q?GF+V+qxSa0qzq82wVlWG/fXz54CL7YS8OVHNQ3CWMxRs3zETWabrLJFiZadc?= =?us-ascii?Q?ajT5oIphPaOqTbSgIFSiGJmSuDGPz/n/CA3XCW7dUV87Ou61vdPEEOhF6n9u?= =?us-ascii?Q?h70dYvBMJta11IRuAlhG8TSGNCTr736D48kbnZBy5gDKgJwyPgASjOuxRujv?= =?us-ascii?Q?rTo/252WwQPk5h1FSorI0ktMJza808dj4+NUABUyv7iQIjviv7CXjy7pUQY5?= =?us-ascii?Q?JJrr6JvpUgxE/n46STTE/7/CRbnCXP/wuYHWNHAWr7sun5T1cFf1Pobp0Ppy?= =?us-ascii?Q?Z1CbtqGhW0u6yO9uasJqn2IKxUkridy0crkqjEQPOU4C/D0lIOWw2wLHqQbz?= =?us-ascii?Q?bqDxKqq3MXZzY9f3Ynwzm3AAti//gVCnqGOHisxYThCbxpiQKtsqSpZmsRqR?= =?us-ascii?Q?xz31jch76wHipCvyt4IGxK0D3228Rill4V/QrHEadW81ptS9L54pXqLQhUbG?= =?us-ascii?Q?88lZ9cRsyKtb4E79XzneZEAjKaOcTs1NS5tjKRZiL93NK43S8a9nWH/jNV8z?= =?us-ascii?Q?h71Ga3rvQJu7vFRwp3HHeu7pKIqLZ95/c41ws87mYu+si0/h+CsUJaHp6ac1?= =?us-ascii?Q?Y5GHlqM2HLq2TFkRVANNvSxhDfOadH2UXPIimRX0?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9861b455-a3a8-4477-34e5-08db416f2fc4 X-MS-Exchange-CrossTenant-AuthSource: DBBPR04MB6140.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 07:16:40.4870 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fGrmEN+at45qyHLBp+dohfqZ+hy3FatETbCgyex56P0R1ArIQSZ+8ipy/aJtYoOa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8094 Received-SPF: pass client-ip=40.107.7.53; envelope-from=GLin@suse.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Apr 2023 07:17:03 -0000 From: Daniel Axtens Do a few things to make libtasn1 compile as part of grub: - redefine _asn1_strcat. grub removed strcat so replace it with the appropriate calls to memcpy and strlen. Use this internally where strcat was used. - replace c_isdigit with grub_isdigit (and don't import c-ctype from gnulib) grub_isdigit provides the same functionality as c_isdigit: it determines if the input is an ASCII digit without regard for locale. - replace GL_ATTRIBUTE_PURE with __attribute__((pure)) which been supported since gcc-2.96. This avoids messing around with gnulib. - adjust libtasn1.h: drop the ASN1_API logic, it's not needed for our modules. Unconditionally support const and pure attributes and adjust header paths. - adjust header paths to "grub/libtasn1.h". - replace a 64 bit division with a call to grub_divmod64, preventing creation of __udivdi3 calls on 32 bit platforms. Signed-off-by: Daniel Axtens Signed-off-by: Gary Lin --- grub-core/lib/libtasn1/lib/decoding.c | 11 +++++----- grub-core/lib/libtasn1/lib/element.c | 3 ++- grub-core/lib/libtasn1/lib/gstr.c | 4 ++-- grub-core/lib/libtasn1/lib/int.h | 4 ++-- grub-core/lib/libtasn1/lib/parser_aux.c | 7 +++--- include/grub/libtasn1.h | 29 +++++++------------------ 6 files changed, 24 insertions(+), 34 deletions(-) diff --git a/grub-core/lib/libtasn1/lib/decoding.c b/grub-core/lib/libtasn1/lib/decoding.c index 92fc87c23..4fd5f0ce6 100644 --- a/grub-core/lib/libtasn1/lib/decoding.c +++ b/grub-core/lib/libtasn1/lib/decoding.c @@ -32,7 +32,8 @@ #include #include #include -#include "c-ctype.h" + +#define c_isdigit grub_isdigit #ifdef DEBUG # define warn() fprintf(stderr, "%s: %d\n", __func__, __LINE__) @@ -2016,8 +2017,8 @@ asn1_expand_octet_string (asn1_node_const definitions, asn1_node * element, (p2->type & CONST_ASSIGN)) { strcpy (name, definitions->name); - strcat (name, "."); - strcat (name, p2->name); + _asn1_strcat (name, "."); + _asn1_strcat (name, p2->name); len = sizeof (value); result = asn1_read_value (definitions, name, value, &len); @@ -2034,8 +2035,8 @@ asn1_expand_octet_string (asn1_node_const definitions, asn1_node * element, if (p2) { strcpy (name, definitions->name); - strcat (name, "."); - strcat (name, p2->name); + _asn1_strcat (name, "."); + _asn1_strcat (name, p2->name); result = asn1_create_element (definitions, name, &aux); if (result == ASN1_SUCCESS) diff --git a/grub-core/lib/libtasn1/lib/element.c b/grub-core/lib/libtasn1/lib/element.c index 5c7941e53..822a1b6ab 100644 --- a/grub-core/lib/libtasn1/lib/element.c +++ b/grub-core/lib/libtasn1/lib/element.c @@ -30,9 +30,10 @@ #include "parser_aux.h" #include #include "structure.h" -#include "c-ctype.h" #include "element.h" +#define c_isdigit grub_isdigit + void _asn1_hierarchical_name (asn1_node_const node, char *name, int name_size) { diff --git a/grub-core/lib/libtasn1/lib/gstr.c b/grub-core/lib/libtasn1/lib/gstr.c index eef419554..bc507d3d8 100644 --- a/grub-core/lib/libtasn1/lib/gstr.c +++ b/grub-core/lib/libtasn1/lib/gstr.c @@ -36,13 +36,13 @@ _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src) if (dest_tot_size - dest_size > str_size) { - strcat (dest, src); + _asn1_strcat (dest, src); } else { if (dest_tot_size > dest_size) { - strncat (dest, src, (dest_tot_size - dest_size) - 1); + memcpy (dest + dest_size, src, (dest_tot_size - dest_size) - 1); dest[dest_tot_size - 1] = 0; } } diff --git a/grub-core/lib/libtasn1/lib/int.h b/grub-core/lib/libtasn1/lib/int.h index d94d51c8c..07dd669ac 100644 --- a/grub-core/lib/libtasn1/lib/int.h +++ b/grub-core/lib/libtasn1/lib/int.h @@ -35,7 +35,7 @@ # include # endif -# include +# include "grub/libtasn1.h" # define ASN1_SMALL_VALUE_SIZE 16 @@ -115,7 +115,7 @@ extern const tag_and_class_st _asn1_tags[]; # define _asn1_strtoul(n,e,b) strtoul((const char *) n, e, b) # define _asn1_strcmp(a,b) strcmp((const char *)a, (const char *)b) # define _asn1_strcpy(a,b) strcpy((char *)a, (const char *)b) -# define _asn1_strcat(a,b) strcat((char *)a, (const char *)b) +# define _asn1_strcat(a,b) memcpy((char *)a + strlen((const char *)a), (const char *)b, strlen((const char *)b) + 1) # if SIZEOF_UNSIGNED_LONG_INT == 8 # define _asn1_strtou64(n,e,b) strtoul((const char *) n, e, b) diff --git a/grub-core/lib/libtasn1/lib/parser_aux.c b/grub-core/lib/libtasn1/lib/parser_aux.c index c05bd2339..8bdc42ae3 100644 --- a/grub-core/lib/libtasn1/lib/parser_aux.c +++ b/grub-core/lib/libtasn1/lib/parser_aux.c @@ -26,7 +26,8 @@ #include "gstr.h" #include "structure.h" #include "element.h" -#include "c-ctype.h" + +#define c_isdigit grub_isdigit char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1]; /* identifier name not found */ @@ -40,7 +41,7 @@ char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1]; /* identifier name not fou #ifdef __clang__ __attribute__((no_sanitize ("integer"))) #endif - _GL_ATTRIBUTE_PURE static unsigned int _asn1_hash_name (const char *x) + __attribute__((__pure__)) static unsigned int _asn1_hash_name (const char *x) { const unsigned char *s = (unsigned char *) x; unsigned h = 0; @@ -632,7 +633,7 @@ _asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE]) count = 0; do { - d = val / 10; + d = grub_divmod64(val, 10, NULL); r = val - d * 10; temp[start + count] = '0' + (char) r; count++; diff --git a/include/grub/libtasn1.h b/include/grub/libtasn1.h index 507e0679e..201089c11 100644 --- a/include/grub/libtasn1.h +++ b/include/grub/libtasn1.h @@ -34,29 +34,16 @@ #ifndef LIBTASN1_H # define LIBTASN1_H -# ifndef ASN1_API -# if defined ASN1_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY -# define ASN1_API __attribute__((__visibility__("default"))) -# elif defined ASN1_BUILDING && defined _MSC_VER && ! defined ASN1_STATIC -# define ASN1_API __declspec(dllexport) -# elif defined _MSC_VER && ! defined ASN1_STATIC -# define ASN1_API __declspec(dllimport) -# else -# define ASN1_API -# endif -# endif +/* grub: ASN1_API is not used */ +# define ASN1_API + +/* grub: all our supported compilers support these attributes */ +# define __LIBTASN1_CONST__ __attribute__((const)) +# define __LIBTASN1_PURE__ __attribute__((pure)) -# ifdef __GNUC__ -# define __LIBTASN1_CONST__ __attribute__((const)) -# define __LIBTASN1_PURE__ __attribute__((pure)) -# else -# define __LIBTASN1_CONST__ -# define __LIBTASN1_PURE__ -# endif -# include -# include -# include /* for FILE* */ +# include +# include # ifdef __cplusplus extern "C" -- 2.35.3