Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pmTmS-00062Y-Vk for mharc-grub-devel@gnu.org; Wed, 12 Apr 2023 02:16:33 -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 1pmTmM-0005zq-5Q for grub-devel@gnu.org; Wed, 12 Apr 2023 02:16:30 -0400 Received: from mail-am6eur05on2085.outbound.protection.outlook.com ([40.107.22.85] helo=EUR05-AM6-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 1pmTmK-0006Qx-0E for grub-devel@gnu.org; Wed, 12 Apr 2023 02:16:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WBCsuiBABQkTmMinplzg++GNh0Fw7ECbYyMEOKQKPwghTYeJYHlPEXchbt9Z6zSIDrq569tELfoZISLYBC0OcIKP+/om8E1F4SnPySRHf+pZ9FFtovdovAAsM73LBMbAilVz2hbcBpM3xrRTlDQNTQtJRyGDSnph1dXTwu0LzHdugejOOJwP5kH/QeSomM9iFjW5cnnssYbwuwzDZzctlw/yC3l8VCG+60qjrGx1cdOZKun4aBSvIlaJ2x3MTHwLqU+kQV/qUkArwTMcWCSTD5Oe4N5ZUW4nxhn18Hkm/9KHiBqiwX5sPqZe0rDcPI98XAEy7lbfe7A9oVBNVfMsxw== 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=mISobphuP9R1EkwJKGbhjgq1F26sPW6AJYRDY9fMy8fTGkQfHL3gn5s7SlMMJKTLzpZCI5IG0GYN++5sDAh6L5+XSnk3WwOB6E3UgdfgihSaPyng5esYqLDhlIyyL5u/lwTByhg+iZekvp8Q/s/iFqz7fl3IWPVxFk5UnutGkVh/Pdab0LEJ1DFfae+dGgh/6+JYzJEHSuj8yDGLPJBNM/EDEXpMst6Jdi0QMUB826tivfa4gERaJ1573hh6YWUuKHYXYDEAW/CT/g0kxWpoL9K1b09n+hEm5P4tyGqUDgOV6FNpa1wQNN3yrW4WErl2M7J1T6Rj/dCT58UisNQQrw== 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=WSLl5uaGYykThsDNsJK9m2utv+bY1jhs1BTHFLe4HAZspH4UCDGOHTpLa46o4W3VU7JhIA+0lG2z3xtxfbqVs71TA/hK1j4in4kcNETSuchJbN1JQjpgpNyrGJyISQLWgxFPgxHrlw/tWa1oZXlIBVF/TtTI/3NrA5MCiCbS+ece83evTp1iG0z0zEtUGkEryBST2YqRsl6w8vVJFhLWSN/0UmSyvY5hZsaRNlxdXJ8zaLE5cng2xHS4vGgYmy6O2F4fhT6mZgoe4GpgbzJDRJkQDfoGlFOO+h4X0iJVhSv1IYbQXdlrKG+NIwdACzui1Z13w3F3n6ZTinRy0+25dw== 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 DU2PR04MB8663.eurprd04.prod.outlook.com (2603:10a6:10:2de::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.30; Wed, 12 Apr 2023 06:16:17 +0000 Received: from DBBPR04MB6140.eurprd04.prod.outlook.com ([fe80::8e45:fffd:c1eb:3ebd]) by DBBPR04MB6140.eurprd04.prod.outlook.com ([fe80::8e45:fffd:c1eb:3ebd%4]) with mapi id 15.20.6277.038; Wed, 12 Apr 2023 06:16:14 +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 v3 04/12] libtasn1: changes for grub compatibility Date: Wed, 12 Apr 2023 14:15:45 +0800 Message-Id: <20230412061553.7597-5-glin@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230412061553.7597-1-glin@suse.com> References: <20230412061553.7597-1-glin@suse.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: FR0P281CA0253.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:af::8) To DBBPR04MB6140.eurprd04.prod.outlook.com (2603:10a6:10:c7::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DBBPR04MB6140:EE_|DU2PR04MB8663:EE_ X-MS-Office365-Filtering-Correlation-Id: b23c2707-8bf6-47c4-2fb0-08db3b1d6b2d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yx97ewmw4GXbtDvzncpAxHVRMBiUbD2jVO9x5C/yCBjBJsXEZUyYLRdlIJ/deXguEk31BEg5uw1t9i1ijKiTiLXykTt/M3gTa7TWwRkBp/Aihl4laI9A/V5FniyfKMYEDGzdOScBgveK7J0Llz/4PqfIetpkoClg2M3VwNcPnt/PM2jdLr2/tJ2clT+jfWSZ1Pwl7Dwnrtw1vFAI52ofPdKvkqAMvmGThb0YKibnuCpgC9RTOwSH2M895WN4F47afVp3Cn1bo8ZI1oFRQHDMNanePmNHtG5bwgjYqig8DyKpFAti2tUnX/AfcT6jSnuq5wmTWAISGlPv8D1J0M42oOsXDbUsovf3R5VVCJfY6EJgIa8V46gkKgGpCKF+bBPpQVrqGnVwxsy10UOukzfUgomRePSIFxH5g2/GT+1HmtRetYw4YrZtt/3vKehn3qy2VFpazrobhi1xBr6PX73QuBcteRt0qUZQnychYVnGWjOQnHIYOglwOQTAh0B+H4rih1Z0SuEfdKAY8eUxpls2pGoYqzFh280pBGzDiwe4zAkJElYiiXSdRr86LCGM+nLI 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)(39860400002)(366004)(346002)(396003)(136003)(376002)(451199021)(83380400001)(107886003)(2616005)(478600001)(6486002)(6666004)(186003)(54906003)(26005)(1076003)(6506007)(6512007)(2906002)(7416002)(36756003)(5660300002)(38100700002)(66556008)(6916009)(4326008)(41300700001)(66476007)(66946007)(316002)(8936002)(86362001)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Pw+A+ZCoDfkNp4VeZND9Qx/nsMxy7x9CJaR43jy6qWYOjdXsSJosSIY3ZAyk?= =?us-ascii?Q?oEa7Chdf0xdgbdzEjuX4SE/0R+7kA9TQE6jZDQ2Zl3e3NTZutAvXTWSOKvE6?= =?us-ascii?Q?vjc6Xiy1j5nk6odOJz4EBisKEHbkT5BA+5RPYyuTi4uufTTpzhx6kmtKt4Qv?= =?us-ascii?Q?1LDKrBt5gH9+YY4K+OumIRu3U4BTajJbq/vW5hrH+R0QuZBiw/VOg/TbO3Ny?= =?us-ascii?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nOAy3cK5KXdMjQThxBSZhLc?= =?us-ascii?Q?IovGHPViiA4QSOYxBJj/ThQoHjB4jdesSwD20LVRgLAsz3jeHT0VFBx5ccnv?= =?us-ascii?Q?ONDhPvk9m2DNYGDzw60Ji8636QYAjiNQ2BPyeemvgdS32fUv26vi/6ppsdkE?= =?us-ascii?Q?KbTzSWe+JgMDB9ha4ehDvHMeKh07DJ9nHHSxnqjf4FhUKZNniaFnFK4+1Uz3?= =?us-ascii?Q?pb/+FKrA1KgfKhhHV9AYFEC2Y3op7/I1ahWohL7Gzn2orhxcZbNm5Lyo8gHU?= =?us-ascii?Q?EMSOiVlrHPeobiKYRC3irMKq12EmiUquD4qkGKigJ463iKk7dVxF8ejNSp+z?= =?us-ascii?Q?g2/A02NWXuTML61VSn2Tj7K5W1K/PYhQ6JU33oqzlQRYYVJh9dAIsaD6lfxZ?= =?us-ascii?Q?7NvuB5Crja7zmITjuE+4ZxSFE9YLbaYa6L9Q3b2DvNO3oSm5zqXl0fflLpMj?= =?us-ascii?Q?OYR8KpfSAbHVQLS8I3U=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: b23c2707-8bf6-47c4-2fb0-08db3b1d6b2d X-MS-Exchange-CrossTenant-AuthSource: DBBPR04MB6140.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2023 06:16:14.4569 (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: pxEY7FjL5T8pAjVhtoqW2qx8i27J7LS/0iIE/+G+6V5AfX7WrlCOtCZM/rIIY+M5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8663 Received-SPF: pass client-ip=40.107.22.85; envelope-from=GLin@suse.com; helo=EUR05-AM6-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 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: Wed, 12 Apr 2023 06:16:30 -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