|
|
5975ab |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
5975ab |
From: Daniel Axtens <dja@axtens.net>
|
|
|
5975ab |
Date: Fri, 1 May 2020 20:44:29 +1000
|
|
|
5975ab |
Subject: [PATCH] libtasn1: changes for grub compatibility
|
|
|
5975ab |
|
|
|
5975ab |
Do a few things to make libtasn1 compile as part of grub:
|
|
|
5975ab |
|
|
|
5975ab |
- replace strcat. grub removed strcat so replace it with the appropriate
|
|
|
5975ab |
calls to memcpy and strlen.
|
|
|
5975ab |
|
|
|
5975ab |
- replace c_isdigit with grub_isdigit (and don't import c-ctype from
|
|
|
5975ab |
gnulib) grub_isdigit provides the same functionality as c_isdigit: it
|
|
|
5975ab |
determines if the input is an ASCII digit without regard for locale.
|
|
|
5975ab |
|
|
|
5975ab |
- replace GL_ATTRIBUTE_PURE with __attribute__((pure)) which been
|
|
|
5975ab |
supported since gcc-2.96. This avoids messing around with gnulib.
|
|
|
5975ab |
|
|
|
5975ab |
- adjust libtasn1.h: drop the ASN1_API logic, it's not needed for our
|
|
|
5975ab |
modules. Unconditionally support const and pure attributes and adjust
|
|
|
5975ab |
header paths.
|
|
|
5975ab |
|
|
|
5975ab |
- adjust header paths to "grub/libtasn1.h".
|
|
|
5975ab |
|
|
|
5975ab |
- replace a 64 bit division with a call to grub_divmod64, preventing
|
|
|
5975ab |
creation of __udivdi3 calls on 32 bit platforms.
|
|
|
5975ab |
|
|
|
5975ab |
Signed-off-by: Daniel Axtens <dja@axtens.net>
|
|
|
5975ab |
---
|
|
|
5975ab |
grub-core/lib/libtasn1/lib/decoding.c | 11 ++++++-----
|
|
|
5975ab |
grub-core/lib/libtasn1/lib/element.c | 3 ++-
|
|
|
5975ab |
grub-core/lib/libtasn1/lib/gstr.c | 4 ++--
|
|
|
5975ab |
grub-core/lib/libtasn1/lib/parser_aux.c | 7 ++++---
|
|
|
5975ab |
grub-core/lib/libtasn1/lib/int.h | 4 ++--
|
|
|
5975ab |
include/grub/libtasn1.h | 26 ++++++--------------------
|
|
|
5975ab |
6 files changed, 22 insertions(+), 33 deletions(-)
|
|
|
5975ab |
|
|
|
5975ab |
diff --git a/grub-core/lib/libtasn1/lib/decoding.c b/grub-core/lib/libtasn1/lib/decoding.c
|
|
|
f6e916 |
index 42f9a92b5..7856858b2 100644
|
|
|
5975ab |
--- a/grub-core/lib/libtasn1/lib/decoding.c
|
|
|
5975ab |
+++ b/grub-core/lib/libtasn1/lib/decoding.c
|
|
|
5975ab |
@@ -32,7 +32,8 @@
|
|
|
5975ab |
#include <element.h>
|
|
|
5975ab |
#include <limits.h>
|
|
|
5975ab |
#include <intprops.h>
|
|
|
5975ab |
-#include <c-ctype.h>
|
|
|
5975ab |
+
|
|
|
5975ab |
+#define c_isdigit grub_isdigit
|
|
|
5975ab |
|
|
|
5975ab |
#ifdef DEBUG
|
|
|
5975ab |
# define warn() fprintf(stderr, "%s: %d\n", __func__, __LINE__)
|
|
|
5975ab |
@@ -2008,8 +2009,8 @@ asn1_expand_octet_string (asn1_node_const definitions, asn1_node * element,
|
|
|
5975ab |
(p2->type & CONST_ASSIGN))
|
|
|
5975ab |
{
|
|
|
5975ab |
strcpy (name, definitions->name);
|
|
|
5975ab |
- strcat (name, ".");
|
|
|
5975ab |
- strcat (name, p2->name);
|
|
|
5975ab |
+ memcpy (name + strlen(name), ".", sizeof(" . "));
|
|
|
5975ab |
+ memcpy (name + strlen(name), p2->name, strlen(p2->name) + 1);
|
|
|
5975ab |
|
|
|
5975ab |
len = sizeof (value);
|
|
|
5975ab |
result = asn1_read_value (definitions, name, value, &len;;
|
|
|
5975ab |
@@ -2026,8 +2027,8 @@ asn1_expand_octet_string (asn1_node_const definitions, asn1_node * element,
|
|
|
5975ab |
if (p2)
|
|
|
5975ab |
{
|
|
|
5975ab |
strcpy (name, definitions->name);
|
|
|
5975ab |
- strcat (name, ".");
|
|
|
5975ab |
- strcat (name, p2->name);
|
|
|
5975ab |
+ memcpy (name + strlen(name), ".", sizeof(" . "));
|
|
|
5975ab |
+ memcpy (name + strlen(name), p2->name, strlen(p2->name) + 1);
|
|
|
5975ab |
|
|
|
5975ab |
result = asn1_create_element (definitions, name, &aux;;
|
|
|
5975ab |
if (result == ASN1_SUCCESS)
|
|
|
5975ab |
diff --git a/grub-core/lib/libtasn1/lib/element.c b/grub-core/lib/libtasn1/lib/element.c
|
|
|
f6e916 |
index 539008d8e..ed761ff56 100644
|
|
|
5975ab |
--- a/grub-core/lib/libtasn1/lib/element.c
|
|
|
5975ab |
+++ b/grub-core/lib/libtasn1/lib/element.c
|
|
|
5975ab |
@@ -30,9 +30,10 @@
|
|
|
5975ab |
#include "parser_aux.h"
|
|
|
5975ab |
#include <gstr.h>
|
|
|
5975ab |
#include "structure.h"
|
|
|
5975ab |
-#include "c-ctype.h"
|
|
|
5975ab |
#include "element.h"
|
|
|
5975ab |
|
|
|
5975ab |
+#define c_isdigit grub_isdigit
|
|
|
5975ab |
+
|
|
|
5975ab |
void
|
|
|
5975ab |
_asn1_hierarchical_name (asn1_node_const node, char *name, int name_size)
|
|
|
5975ab |
{
|
|
|
5975ab |
diff --git a/grub-core/lib/libtasn1/lib/gstr.c b/grub-core/lib/libtasn1/lib/gstr.c
|
|
|
f6e916 |
index e91a3a151..e33875c2c 100644
|
|
|
5975ab |
--- a/grub-core/lib/libtasn1/lib/gstr.c
|
|
|
5975ab |
+++ b/grub-core/lib/libtasn1/lib/gstr.c
|
|
|
5975ab |
@@ -36,13 +36,13 @@ _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src)
|
|
|
5975ab |
|
|
|
5975ab |
if (dest_tot_size - dest_size > str_size)
|
|
|
5975ab |
{
|
|
|
5975ab |
- strcat (dest, src);
|
|
|
5975ab |
+ memcpy (dest + dest_size, src, str_size + 1);
|
|
|
5975ab |
}
|
|
|
5975ab |
else
|
|
|
5975ab |
{
|
|
|
5975ab |
if (dest_tot_size - dest_size > 0)
|
|
|
5975ab |
{
|
|
|
5975ab |
- strncat (dest, src, (dest_tot_size - dest_size) - 1);
|
|
|
5975ab |
+ memcpy (dest + dest_size, src, (dest_tot_size - dest_size) - 1);
|
|
|
5975ab |
dest[dest_tot_size - 1] = 0;
|
|
|
5975ab |
}
|
|
|
5975ab |
}
|
|
|
5975ab |
diff --git a/grub-core/lib/libtasn1/lib/parser_aux.c b/grub-core/lib/libtasn1/lib/parser_aux.c
|
|
|
f6e916 |
index d5dbbf876..89c9be69d 100644
|
|
|
5975ab |
--- a/grub-core/lib/libtasn1/lib/parser_aux.c
|
|
|
5975ab |
+++ b/grub-core/lib/libtasn1/lib/parser_aux.c
|
|
|
5975ab |
@@ -26,7 +26,8 @@
|
|
|
5975ab |
#include "gstr.h"
|
|
|
5975ab |
#include "structure.h"
|
|
|
5975ab |
#include "element.h"
|
|
|
5975ab |
-#include "c-ctype.h"
|
|
|
5975ab |
+
|
|
|
5975ab |
+#define c_isdigit grub_isdigit
|
|
|
5975ab |
|
|
|
5975ab |
char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1]; /* identifier name not found */
|
|
|
5975ab |
|
|
|
5975ab |
@@ -40,7 +41,7 @@ char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1]; /* identifier name not fou
|
|
|
5975ab |
#ifdef __clang__
|
|
|
5975ab |
__attribute__((no_sanitize("integer")))
|
|
|
5975ab |
#endif
|
|
|
5975ab |
-_GL_ATTRIBUTE_PURE
|
|
|
5975ab |
+__attribute__((__pure__))
|
|
|
5975ab |
static unsigned int
|
|
|
5975ab |
_asn1_hash_name (const char *x)
|
|
|
5975ab |
{
|
|
|
5975ab |
@@ -634,7 +635,7 @@ _asn1_ltostr (int64_t v, char str[LTOSTR_MAX_SIZE])
|
|
|
5975ab |
count = 0;
|
|
|
5975ab |
do
|
|
|
5975ab |
{
|
|
|
5975ab |
- d = val / 10;
|
|
|
5975ab |
+ d = grub_divmod64(val, 10, NULL);
|
|
|
5975ab |
r = val - d * 10;
|
|
|
5975ab |
temp[start + count] = '0' + (char) r;
|
|
|
5975ab |
count++;
|
|
|
5975ab |
diff --git a/grub-core/lib/libtasn1/lib/int.h b/grub-core/lib/libtasn1/lib/int.h
|
|
|
f6e916 |
index ea1625786..4a568efee 100644
|
|
|
5975ab |
--- a/grub-core/lib/libtasn1/lib/int.h
|
|
|
5975ab |
+++ b/grub-core/lib/libtasn1/lib/int.h
|
|
|
5975ab |
@@ -35,7 +35,7 @@
|
|
|
5975ab |
#include <sys/types.h>
|
|
|
5975ab |
#endif
|
|
|
5975ab |
|
|
|
5975ab |
-#include <libtasn1.h>
|
|
|
5975ab |
+#include "grub/libtasn1.h"
|
|
|
5975ab |
|
|
|
5975ab |
#define ASN1_SMALL_VALUE_SIZE 16
|
|
|
5975ab |
|
|
|
5975ab |
@@ -115,7 +115,7 @@ extern const tag_and_class_st _asn1_tags[];
|
|
|
5975ab |
#define _asn1_strtoul(n,e,b) strtoul((const char *) n, e, b)
|
|
|
5975ab |
#define _asn1_strcmp(a,b) strcmp((const char *)a, (const char *)b)
|
|
|
5975ab |
#define _asn1_strcpy(a,b) strcpy((char *)a, (const char *)b)
|
|
|
5975ab |
-#define _asn1_strcat(a,b) strcat((char *)a, (const char *)b)
|
|
|
5975ab |
+#define _asn1_strcat(a,b) memcpy((char *)a + strlen((const char *)a), (const char *)b, strlen((const char *)b) + 1)
|
|
|
5975ab |
|
|
|
5975ab |
#if SIZEOF_UNSIGNED_LONG_INT == 8
|
|
|
5975ab |
# define _asn1_strtou64(n,e,b) strtoul((const char *) n, e, b)
|
|
|
5975ab |
diff --git a/include/grub/libtasn1.h b/include/grub/libtasn1.h
|
|
|
f6e916 |
index 785eda2ae..28dbf16c4 100644
|
|
|
5975ab |
--- a/include/grub/libtasn1.h
|
|
|
5975ab |
+++ b/include/grub/libtasn1.h
|
|
|
5975ab |
@@ -38,29 +38,15 @@
|
|
|
5975ab |
#ifndef LIBTASN1_H
|
|
|
5975ab |
#define LIBTASN1_H
|
|
|
5975ab |
|
|
|
5975ab |
-#ifndef ASN1_API
|
|
|
5975ab |
-#if defined ASN1_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY
|
|
|
5975ab |
-#define ASN1_API __attribute__((__visibility__("default")))
|
|
|
5975ab |
-#elif defined ASN1_BUILDING && defined _MSC_VER && ! defined ASN1_STATIC
|
|
|
5975ab |
-#define ASN1_API __declspec(dllexport)
|
|
|
5975ab |
-#elif defined _MSC_VER && ! defined ASN1_STATIC
|
|
|
5975ab |
-#define ASN1_API __declspec(dllimport)
|
|
|
5975ab |
-#else
|
|
|
5975ab |
+/* grub: ASN1_API is not used */
|
|
|
5975ab |
#define ASN1_API
|
|
|
5975ab |
-#endif
|
|
|
5975ab |
-#endif
|
|
|
5975ab |
|
|
|
5975ab |
-#ifdef __GNUC__
|
|
|
5975ab |
-# define __LIBTASN1_CONST__ __attribute__((const))
|
|
|
5975ab |
-# define __LIBTASN1_PURE__ __attribute__((pure))
|
|
|
5975ab |
-#else
|
|
|
5975ab |
-# define __LIBTASN1_CONST__
|
|
|
5975ab |
-# define __LIBTASN1_PURE__
|
|
|
5975ab |
-#endif
|
|
|
5975ab |
+/* grub: all our supported compilers support these attributes */
|
|
|
5975ab |
+#define __LIBTASN1_CONST__ __attribute__((const))
|
|
|
5975ab |
+#define __LIBTASN1_PURE__ __attribute__((pure))
|
|
|
5975ab |
|
|
|
5975ab |
-#include <sys/types.h>
|
|
|
5975ab |
-#include <time.h>
|
|
|
5975ab |
-#include <stdio.h> /* for FILE* */
|
|
|
5975ab |
+#include <grub/types.h>
|
|
|
5975ab |
+#include <grub/time.h>
|
|
|
5975ab |
|
|
|
5975ab |
#ifdef __cplusplus
|
|
|
5975ab |
extern "C"
|