From: Gary Lin via Grub-devel <grub-devel@gnu.org>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: Gary Lin <glin@suse.com>,
Hernan Gatta <hegatta@linux.microsoft.com>,
Daniel Axtens <dja@axtens.net>,
'Daniel Kiper ' <dkiper@net-space.pl>,
shkhisti@microsoft.com, jaskaran.khurana@microsoft.com,
christopher.co@microsoft.com, daniel.mihai@microsoft.com,
jaredz@redhat.com, development@efficientek.com,
jejb@linux.ibm.com, mchang@suse.com
Subject: [PATCH v7 04/20] libtasn1: changes for grub compatibility
Date: Mon, 20 Nov 2023 15:16:28 +0800 [thread overview]
Message-ID: <20231120071644.14547-5-glin@suse.com> (raw)
In-Reply-To: <20231120071644.14547-1-glin@suse.com>
From: Daniel Axtens <dja@axtens.net>
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 <dja@axtens.net>
Signed-off-by: Gary Lin <glin@suse.com>
---
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 <element.h>
#include <limits.h>
#include <intprops.h>
-#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 <gstr.h>
#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 <sys/types.h>
# endif
-# include <libtasn1.h>
+# 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 <sys/types.h>
-# include <time.h>
-# include <stdio.h> /* for FILE* */
+# include <grub/types.h>
+# include <grub/time.h>
# ifdef __cplusplus
extern "C"
--
2.35.3
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next prev parent reply other threads:[~2023-11-20 7:17 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-20 7:16 [PATCH v7 00/20] Automatic Disk Unlock with TPM2 Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 01/20] posix_wrap: tweaks in preparation for libtasn1 Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 02/20] libtasn1: import libtasn1-4.19.0 Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 03/20] libtasn1: disable code not needed in grub Gary Lin via Grub-devel
2023-11-20 7:16 ` Gary Lin via Grub-devel [this message]
2023-11-20 7:16 ` [PATCH v7 05/20] libtasn1: compile into asn1 module Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 06/20] test_asn1: test module for libtasn1 Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 07/20] libtasn1: Add the documentation Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 08/20] protectors: Add key protectors framework Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 09/20] tpm2: Add TPM Software Stack (TSS) Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 10/20] protectors: Add TPM2 Key Protector Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 11/20] cryptodisk: Support key protectors Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 12/20] util/grub-protect: Add new tool Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 13/20] tpm2: Add TPM2 types, structures, and command constants Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 14/20] tpm2: Add more marshal/unmarshal functions Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 15/20] tpm2: Implement more TPM2 commands Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 16/20] tpm2: Support authorized policy Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 17/20] protectors: Implement NV index Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 18/20] cryptodisk: Fallback to passphrase Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 19/20] cryptodisk: wipe out the cached keys from protectors Gary Lin via Grub-devel
2023-11-20 7:16 ` [PATCH v7 20/20] diskfilter: look up cryptodisk devices first Gary Lin via Grub-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231120071644.14547-5-glin@suse.com \
--to=grub-devel@gnu.org \
--cc=christopher.co@microsoft.com \
--cc=daniel.mihai@microsoft.com \
--cc=development@efficientek.com \
--cc=dja@axtens.net \
--cc=dkiper@net-space.pl \
--cc=glin@suse.com \
--cc=hegatta@linux.microsoft.com \
--cc=jaredz@redhat.com \
--cc=jaskaran.khurana@microsoft.com \
--cc=jejb@linux.ibm.com \
--cc=mchang@suse.com \
--cc=shkhisti@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).