Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1m2vce-0004re-1H for mharc-grub-devel@gnu.org; Mon, 12 Jul 2021 09:05:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2vcU-0004nG-Cx for grub-devel@gnu.org; Mon, 12 Jul 2021 09:05:10 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:36128) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2vcR-0006US-UK for grub-devel@gnu.org; Mon, 12 Jul 2021 09:05:10 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16CD3cPc018286; Mon, 12 Jul 2021 09:05:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=KmDMQTUushROdWcSsctd+vR+424Gm2TXs5Aa5S31rFA=; b=S8guOxtt2Iv7qFWhtgmn8TJpnybvPTP6+LgGBV2ShMJur5YpZoc2/lk/nKx+Ail6LSC6 Ih4ux1tAjYZvt4mfM7oHLCL4VYCLfscRQFaNMLYkmdvLAVT0263SZUivxS+uOSfVYNnT MpqBo/3vjWaejqjiGinT2c15RXH0adKMD9gEckb0e3DNxBd3S5A+yk1kUWdOaGzUAlbL 37PjSHvdYBMN0w1I+zJUa3bCJaoy6Uvaod4Opv7UtGy+XKGVsL0IxNaQ2vp+7FRz/eAr JPRwpmYHEA3jKIwo1h8PwO+zPK+MvPWXNo4OA42bwOe1Qofz2L9f1YS/XBiJefrjrkxf vg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 39qruchakm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 Jul 2021 09:05:03 -0400 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 16CD3mCp019232; Mon, 12 Jul 2021 09:05:03 -0400 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com with ESMTP id 39qruchak4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 Jul 2021 09:05:03 -0400 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 16CD4AWV029689; Mon, 12 Jul 2021 13:05:02 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma02dal.us.ibm.com with ESMTP id 39qt39tdr2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 Jul 2021 13:04:58 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 16CD4d3t36176364 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Jul 2021 13:04:39 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C7FCCAE060; Mon, 12 Jul 2021 13:04:38 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B91E6AE06A; Mon, 12 Jul 2021 13:04:38 +0000 (GMT) Received: from [9.47.158.152] (unknown [9.47.158.152]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 12 Jul 2021 13:04:38 +0000 (GMT) Subject: Re: [PATCH v2 13/22] libtasn1: changes for grub compatibility To: The development of GNU GRUB , Daniel Axtens Cc: rashmica.g@gmail.com, alastair@d-silva.org, nayna@linux.ibm.com References: <20210630084031.2663622-1-dja@axtens.net> <20210630084031.2663622-14-dja@axtens.net> From: Stefan Berger Message-ID: <1343acd9-f663-c883-9fc6-3f552103fb62@linux.ibm.com> Date: Mon, 12 Jul 2021 09:04:38 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210630084031.2663622-14-dja@axtens.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-GUID: l7WQ9rWmbrrh-IGwIhuJ3-6gk0hR1a6M X-Proofpoint-ORIG-GUID: 9U4IH7YKn9YKged33UeegsMEYuB5B-wI X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-12_08:2021-07-12, 2021-07-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 spamscore=0 mlxlogscore=999 impostorscore=0 bulkscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107120103 Received-SPF: pass client-ip=148.163.158.5; envelope-from=stefanb@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-1.479, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jul 2021 13:05:11 -0000 On 6/30/21 4:40 AM, Daniel Axtens wrote: > 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 > > --- > > v2: Clean up strcat handling, thanks Stefan Berger. > --- > 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 | 26 ++++++------------------- > 6 files changed, 22 insertions(+), 33 deletions(-) > > diff --git a/grub-core/lib/libtasn1/lib/decoding.c b/grub-core/lib/libtasn1/lib/decoding.c > index 42f9a92b5d44..3406e1832746 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 > + > +#define c_isdigit grub_isdigit > > #ifdef DEBUG > # define warn() fprintf(stderr, "%s: %d\n", __func__, __LINE__) > @@ -2008,8 +2009,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); > @@ -2026,8 +2027,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 539008d8e949..ed761ff56bd9 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 e91a3a151c0d..a092c9a5a24b 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 > 0) > { > - strncat (dest, src, (dest_tot_size - dest_size) - 1); > + memcpy (dest + dest_size, src, (dest_tot_size - dest_size) - 1); With dest_size = strlen(dest) this is following the 'pattern' of the #define below. > 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 ea1625786c1b..4a568efee9c1 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 d5dbbf8765da..89c9be69dc2a 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 > +__attribute__((__pure__)) > static unsigned int > _asn1_hash_name (const char *x) > { > @@ -634,7 +635,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 785eda2ae3f8..28dbf16c4e0c 100644 > --- a/include/grub/libtasn1.h > +++ b/include/grub/libtasn1.h > @@ -38,29 +38,15 @@ > #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 > +/* grub: ASN1_API is not used */ > #define ASN1_API > -#endif > -#endif > > -#ifdef __GNUC__ > -# define __LIBTASN1_CONST__ __attribute__((const)) > -# define __LIBTASN1_PURE__ __attribute__((pure)) > -#else > -# define __LIBTASN1_CONST__ > -# define __LIBTASN1_PURE__ > -#endif > +/* grub: all our supported compilers support these attributes */ > +#define __LIBTASN1_CONST__ __attribute__((const)) > +#define __LIBTASN1_PURE__ __attribute__((pure)) > > -#include > -#include > -#include /* for FILE* */ > +#include > +#include > > #ifdef __cplusplus > extern "C" Reviewed-by: Stefan Berger