dcavalca / rpms / grub2

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