Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1petZ8-00033z-Bi for mharc-grub-devel@gnu.org; Wed, 22 Mar 2023 04:11:26 -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 1petZ6-00033h-A8 for grub-devel@gnu.org; Wed, 22 Mar 2023 04:11:24 -0400 Received: from mail-ve1eur01on2044.outbound.protection.outlook.com ([40.107.14.44] helo=EUR01-VE1-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 1petZ4-0002y4-Hr for grub-devel@gnu.org; Wed, 22 Mar 2023 04:11:24 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HeV+9cg/KRCj73ctTOP3hvqdu1jDwr57ZfbN9mBUibQvUPWG845WATfQKdE8AL02g6cpKZbMakITVtIzcxjZQ867s0ePWpofNjrsYp1iO1DdQqTD97hux/jjOuv/P+QKYI6YeRHrQ/sPtL0HaDbP6BAxYqhSCopfa8gBZt2lQk69jRE6yOPAd7a1hlEVgNC9DrBKcGTg7855o+AJPyVjRzG+sJgsGrcRWpcXQSYcwv55iPauPUst1tVao7sGYtYQp4vtO5ZjtU4MVMY0H2PprOBQ+VSwRKd1pEI0AnmVnOfYgGHdyQ9Rv6aJ/LnUum8QjsdqRahlTZHl6IgYsNM+Uw== 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=nC4v3TtVSKeI0XFdxNRntdEqqa6TsJURG2B67Gph4xLC+9gtHtJ9PnPTPf/bgqU4PzIzz44lGkMD/dRhl9sCnnzeYYgT0xR/n01OxJgxOvi0LIGrj0J3mIksrHVlvCcKHda2YCgGFErlv7CXbJgMTwKwLhretzKQQkE1keC1Ic8vP8gfv3EkZEfQ012T1mDLQUjo4wDwbgE9gTgJVg6SaK2A0fL9pRNBnJbqfyqNsBn+SNsj0jD0mypjXtNdIV3UPTIOTsQZGoHzOGGgjw4F1q8tuK5jCNEoU9Ad/tKVspEO944CGn6RRWGBI1KWOpklYPcjXEbfenzDGIWVP+YKZw== 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=sz4Aipz4s84ndJncqE9Qe2C76oybePpGsw4BEtYjSH+IHvdT5I2uPBPuwPWfhcOrairqW9XDy7i2CTdwdf5igUMvKwCDpV15tA7yZ7Xpi3Gk4sYsbR6LsE44TbPMs6UnLaGTuLcU2M1XBIOfuFhhSY25+c3XX4ziom/So+4LkQEL8HEI4TstvTj0yRNKC4j0c+f5ZzWxgmwyhNc4e7oMXGHH51OGjzhjetmDhVejVfH5xlhZVHbF307jYx1dwNA6K7LlLEmSot2yr6M13NoQMu9x58lu2Ut6b5YPR8uNgzSWRVc7/Lbees0gj98mQo+xgobyRjWo9VvctDfCIhAJig== 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 VE1PR04MB7360.eurprd04.prod.outlook.com (2603:10a6:800:1a3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Wed, 22 Mar 2023 08:11:03 +0000 Received: from DBBPR04MB6140.eurprd04.prod.outlook.com ([fe80::688f:bc10:59e2:772a]) by DBBPR04MB6140.eurprd04.prod.outlook.com ([fe80::688f:bc10:59e2:772a%6]) with mapi id 15.20.6178.037; Wed, 22 Mar 2023 08:11:03 +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 v2 04/11] libtasn1: changes for grub compatibility Date: Wed, 22 Mar 2023 16:10:09 +0800 Message-Id: <20230322081016.12075-5-glin@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230322081016.12075-1-glin@suse.com> References: <20230322081016.12075-1-glin@suse.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TYCPR01CA0184.jpnprd01.prod.outlook.com (2603:1096:400:2b0::13) To DBBPR04MB6140.eurprd04.prod.outlook.com (2603:10a6:10:c7::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DBBPR04MB6140:EE_|VE1PR04MB7360:EE_ X-MS-Office365-Filtering-Correlation-Id: 1509c2a9-705e-4764-bab5-08db2aacfa6e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k6NZWQlQUxY2oMMt0b+e7LSFFhBijiNWu189xe0DLR+6HGnhNz7jBTo3IiWm99OkFcmCpf9wslmWA5s8nzHkwSLi3FMTxU++sVatXqVvoIjOmcSvFoNuzMMLdHruRZoyap6A3kbVgx0O8ZLsKb0BkUqgygrlHynkBHbGtmG+OLf9Mz17TPw8uHv6Q0gY6c0IpeHPuDIC6FEDG2rmL1gNrZaiU0xMFU9rWypzBQgnNMb4JV/VEbGgo1iCbpEc9CRhLoG1nKGjJx7YHuwrU6ICRs2RkkI6B4yVDhmgXNHpp7MBB926ZA9i53eK/0FSqPpZ7LjoUgNgzR8yzLMPueVdlAl66+sTUI/IP9FuyNPlus3tunVWLtJmx+JvBraSxOjtqkYe6ZUy8CpJBVClRIqwTEsVnYOFZI4Lv83xVYbEsv9vWA0LWoZK1aIhE4nL97OLrdvJLVQOsWSLQSNJ+1bk3oF4IyEkkDd25XUq0zPc/AkHaSaKLs7eaj3zcFBXwIWRZ9fVT81renaV3lFKjFh3KwCdb3uIGQOD8aODgrn2ixciJYZdi3Zzo2o9udfrEUY7qsoNnCoJePaeJ/sbJIT+bdMmsmfWWrGmOHmZfEI7ITuQlXrLnRU5KBJDznIela4hm4I1vsu67J7ZYQzoIsCRQA== 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:(13230025)(366004)(39850400004)(346002)(396003)(136003)(376002)(451199018)(2616005)(107886003)(6512007)(6486002)(186003)(1076003)(26005)(83380400001)(6506007)(54906003)(38100700002)(2906002)(478600001)(86362001)(4326008)(316002)(8676002)(66946007)(8936002)(7416002)(66556008)(66476007)(5660300002)(41300700001)(36756003)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?viYqsin1icuzwVwAqRbb7Xp0zfmzNSi5zoDfjPWDGqJz6WzF2Wqc0ZQUcYN8?= =?us-ascii?Q?bPagH59znSjq6yRr8IIcaa5eE84v6QDI1wajpbTKl2UOU//ZKCS9T4eaiP7w?= =?us-ascii?Q?MS6LFrFSjEa1knD/RTKMbmBLN3wlqphvqcR6DTmW4DmFY55k74UIXLWxheBa?= =?us-ascii?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XvmK6vxNnXuo+ArwDcaJsrtiFON?= =?us-ascii?Q?m7/FsHjtyOslqZH9Ej25cbE7zAcCpDNP3ib25P20K52DBNDQ7iI7GAUqLRnL?= =?us-ascii?Q?6wHmhj4mrX4hgkwLYzsHfE2AmMVJB4dNQZmqlpzt7vEdGXfOqEJzE9rv+QxB?= =?us-ascii?Q?wN32kDjpcv6MPhHK0f/uFqhJMhY469BvDV+jAI62UbO69xIQ06SHnd39AIsR?= =?us-ascii?Q?m5T+ynLN+KfbXffwevd/XzxabWvOz6cJP28VSZoY9q9vx54/tHpQT/Vl4PMP?= =?us-ascii?Q?UJaoCEYaG8KD8MELFHrtHHYEcnEu/Tn32tqqTnqod48g22wgQ50YgyF21unO?= =?us-ascii?Q?+I2aWIaUFWr0jDYFQ8ANj3yMNG4h51aw6lqbGQ0Dq2b2uJrEuUNXXdmft/Om?= =?us-ascii?Q?W2uaohWP5AsjacbXMxM1KD2GMnuoyzjsNrlX0+JT+3nosdToCHdZaYrwNc7g?= =?us-ascii?Q?n7WcRQhVcTjrSo8Ijy59nkTs170tcTBHWRnXULd37Jbo2c5ry+mxiYLmJr2j?= =?us-ascii?Q?nLLpFwcggDT96z/AHkH3FtUtVrx3W9VAiH+ffsZt?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1509c2a9-705e-4764-bab5-08db2aacfa6e X-MS-Exchange-CrossTenant-AuthSource: DBBPR04MB6140.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2023 08:11:02.9390 (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: phz+E3+tIhD/LjGwEru3SvSBXrHjOoHc/1IGV/hmrySShySMhxF8cd5GCatWEG9T X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7360 Received-SPF: pass client-ip=40.107.14.44; envelope-from=GLin@suse.com; helo=EUR01-VE1-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, 22 Mar 2023 08:11:24 -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