Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kODOc-0003lv-1t for mharc-grub-devel@gnu.org; Fri, 02 Oct 2020 01:14:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kODOZ-0003gl-T7 for grub-devel@gnu.org; Fri, 02 Oct 2020 01:14:15 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:35826) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kODOX-00057w-Ik for grub-devel@gnu.org; Fri, 02 Oct 2020 01:14:15 -0400 Received: by mail-pj1-x1035.google.com with SMTP id x2so164999pjk.0 for ; Thu, 01 Oct 2020 22:14:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aXASSkx4AY2Ln8eIR//qy8pGuxn+HMDf1XZyFUjT4EM=; b=KVRMEMo4tx3o0JFNPOnKvKcmelQhAX0XJZCwNZ34kHMihNrmH9ik8+/5pIBdKJDubg 3NO6IZ4o5FzZZ9+Tp5aLkGzycXpQdpMJUBjJjcNdvJCncYCD1mehwPQBJ/6t8Bj+wsHc 3oMC4ZupcMRs0hsqa3r5nzjexNpZQD8uFwtkA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aXASSkx4AY2Ln8eIR//qy8pGuxn+HMDf1XZyFUjT4EM=; b=PP/qyriyRi46bSDzOqJfpdMlY8AFnt3hC9sh3p0eqqZKEsWwt3/rpOBWiCd1erX/Eb N1w3I0k1PL33JjuD9FoC5avn+VdMxue4i3ZRodb4gVQLDSZyz9WmUnVHEzD6NK3dZUAw OBSDhSa1DQWjT9iyTahefIRQDqVQZsXVcCLs9QdmFmIhQk0V/oY3PHH9bKKVzhChhPJ8 zi2FRrt4z0OE2h0uggxEqSTKdtjqBbbMOA+ml/diJQBrFRi6RoadIPTIOrSkvOVtcn86 /X0KXSF3HLwFVk6ufUpvvkZndViQNN/jl5+LKjXM86PQMddodPjwQ/4/pW1OvlXsy91l I65g== X-Gm-Message-State: AOAM531OmQHXoaBU8e+TaCUtxoXOOKKZOCW+kAJYPe5wSlhqBiX1rYzx ddaBSUCO2VAnZwSAinV1SVmilZyskt0DUQ== X-Google-Smtp-Source: ABdhPJyzyBvmFoRgNesKd2Wwx/ifIrfnIieDKYdHXz3HJZ+y6RxWcfTcH8YicWD7RHfSJbtCn0416Q== X-Received: by 2002:a17:90a:ed8e:: with SMTP id k14mr895281pjy.178.1601615651782; Thu, 01 Oct 2020 22:14:11 -0700 (PDT) Received: from localhost (2001-44b8-111e-5c00-804e-30c2-4157-6268.static.ipv6.internode.on.net. [2001:44b8:111e:5c00:804e:30c2:4157:6268]) by smtp.gmail.com with ESMTPSA id u2sm338469pfk.85.2020.10.01.22.14.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2020 22:14:11 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: rashmica.g@gmail.com, alastair@d-silva.org, Daniel Axtens Subject: [PATCH 10/18] libtasn1: changes for grub compatibility Date: Fri, 2 Oct 2020 15:13:13 +1000 Message-Id: <20201002051321.1538488-11-dja@axtens.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201002051321.1538488-1-dja@axtens.net> References: <20201002051321.1538488-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=dja@axtens.net; helo=mail-pj1-x1035.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, 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: Fri, 02 Oct 2020 05:14:16 -0000 Do a few things to make libtasn1 compile as part of grub: - replace strcat. grub removed strcat so replace it with the appropriate calls to memcpy and strlen. - 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 --- 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..7856858b2727 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); + memcpy (name + strlen(name), ".", sizeof(" . ")); + memcpy (name + strlen(name), p2->name, strlen(p2->name) + 1); 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); + memcpy (name + strlen(name), ".", sizeof(" . ")); + memcpy (name + strlen(name), p2->name, strlen(p2->name) + 1); 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..e33875c2c7c5 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); + memcpy (dest + dest_size, src, str_size + 1); } 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); 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" -- 2.25.1