[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v19 14/33] asn1_test: use the grub-specific functions and types
From: |
Gary Lin |
Subject: |
[PATCH v19 14/33] asn1_test: use the grub-specific functions and types |
Date: |
Fri, 6 Sep 2024 17:11:06 +0800 |
This commit converts functions and types to the grub-specific ones:
LONG_MAX -> GRUB_LONG_MAX
INT_MAX -> GRUB_INT_MAX
UINT_MAX -> GRUB_UINT_MAX
size_t -> grub_size_t
memcmp() -> grub_memcmp()
memcpy() -> grub_memcpy()
free() -> grub_free()
strcmp() -> grub_strcmp()
Signed-off-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Gary Lin <glin@suse.com>
---
...he-grub-specific-functions-and-types.patch | 262 ++++++++++++++++++
1 file changed, 262 insertions(+)
create mode 100644
grub-core/lib/libtasn1-patches/0012-asn1_test-use-the-grub-specific-functions-and-types.patch
diff --git
a/grub-core/lib/libtasn1-patches/0012-asn1_test-use-the-grub-specific-functions-and-types.patch
b/grub-core/lib/libtasn1-patches/0012-asn1_test-use-the-grub-specific-functions-and-types.patch
new file mode 100644
index 000000000..b5cf0fad6
--- /dev/null
+++
b/grub-core/lib/libtasn1-patches/0012-asn1_test-use-the-grub-specific-functions-and-types.patch
@@ -0,0 +1,262 @@
+From 625c23cdb7599ee4fa5e4991864fb69ccb89cae3 Mon Sep 17 00:00:00 2001
+From: Gary Lin <glin@suse.com>
+Date: Fri, 16 Aug 2024 15:46:59 +0800
+Subject: [PATCH 12/12] asn1_test: use the grub-specific functions and types
+
+This commit converts functions and types to the grub-specific ones:
+
+LONG_MAX -> GRUB_LONG_MAX
+INT_MAX -> GRUB_INT_MAX
+UINT_MAX -> GRUB_UINT_MAX
+size_t -> grub_size_t
+memcmp() -> grub_memcmp()
+memcpy() -> grub_memcpy()
+free() -> grub_free()
+strcmp() -> grub_strcmp()
+
+Signed-off-by: Daniel Axtens <dja@axtens.net>
+Signed-off-by: Gary Lin <glin@suse.com>
+---
+ grub-core/tests/asn1/tests/Test_overflow.c | 4 ++--
+ grub-core/tests/asn1/tests/Test_simple.c | 22 +++++++++----------
+ grub-core/tests/asn1/tests/Test_strings.c | 8 +++----
+ .../tests/asn1/tests/object-id-decoding.c | 4 ++--
+ .../tests/asn1/tests/object-id-encoding.c | 2 +-
+ grub-core/tests/asn1/tests/octet-string.c | 10 ++++-----
+ 6 files changed, 25 insertions(+), 25 deletions(-)
+
+diff --git a/grub-core/tests/asn1/tests/Test_overflow.c
b/grub-core/tests/asn1/tests/Test_overflow.c
+index ffac8507a..65843abf6 100644
+--- a/grub-core/tests/asn1/tests/Test_overflow.c
++++ b/grub-core/tests/asn1/tests/Test_overflow.c
+@@ -43,9 +43,9 @@ test_overflow (void)
+
+ /* Test that values larger than int but smaller than long are
+ rejected. This limitation was introduced with libtasn1 2.12. */
+- if (LONG_MAX > INT_MAX)
++ if (GRUB_LONG_MAX > GRUB_INT_MAX)
+ {
+- unsigned long num = ((long) UINT_MAX) << 2;
++ unsigned long num = ((long) GRUB_UINT_MAX) << 2;
+ unsigned char der[20];
+ int der_len;
+ long l;
+diff --git a/grub-core/tests/asn1/tests/Test_simple.c
b/grub-core/tests/asn1/tests/Test_simple.c
+index dc70db191..19613cae8 100644
+--- a/grub-core/tests/asn1/tests/Test_simple.c
++++ b/grub-core/tests/asn1/tests/Test_simple.c
+@@ -81,7 +81,7 @@ test_simple (void)
+ int der_len = sizeof (der);
+ int str_size = sizeof (str);
+ int ret_len, bit_len;
+- size_t i;
++ grub_size_t i;
+
+ {
+ unsigned int etype = 38;
+@@ -127,7 +127,7 @@ test_simple (void)
+ }
+ #endif
+
+- if (der_len != tv[i].derlen || memcmp (der, tv[i].der, der_len) != 0)
++ if (der_len != tv[i].derlen || grub_memcmp (der, tv[i].der, der_len) !=
0)
+ {
+ grub_printf ("asn1_bit_der iter %lu\n", (unsigned long) i);
+ return 1;
+@@ -155,12 +155,12 @@ test_simple (void)
+
+ /* 03 04 06 6e 5d c0 DER encoding */
+
+- memcpy (der, "\x04\x06\x6e\x5d\xc0", 5);
++ grub_memcpy (der, "\x04\x06\x6e\x5d\xc0", 5);
+ der_len = 5;
+
+ result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len);
+ if (result != ASN1_SUCCESS || ret_len != 5
+- || bit_len != 18 || memcmp (str, "\x6e\x5d\xc0", 3) != 0)
++ || bit_len != 18 || grub_memcmp (str, "\x6e\x5d\xc0", 3) != 0)
+ {
+ grub_printf ("asn1_get_bit_der example\n");
+ return 1;
+@@ -168,7 +168,7 @@ test_simple (void)
+
+ der_len = sizeof (der);
+ asn1_bit_der (str, bit_len, der, &der_len);
+- if (der_len != 5 || memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0)
++ if (der_len != 5 || grub_memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0)
+ {
+ grub_printf ("asn1_bit_der example roundtrip\n");
+ return 1;
+@@ -176,12 +176,12 @@ test_simple (void)
+
+ /* 03 04 06 6e 5d e0 padded with "100000" */
+
+- memcpy (der, "\x04\x06\x6e\x5d\xe0", 5);
++ grub_memcpy (der, "\x04\x06\x6e\x5d\xe0", 5);
+ der_len = 5;
+
+ result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len);
+ if (result != ASN1_SUCCESS || ret_len != 5
+- || bit_len != 18 || memcmp (str, "\x6e\x5d\xe0", 3) != 0)
++ || bit_len != 18 || grub_memcmp (str, "\x6e\x5d\xe0", 3) != 0)
+ {
+ grub_printf ("asn1_get_bit_der example padded\n");
+ return 1;
+@@ -189,7 +189,7 @@ test_simple (void)
+
+ der_len = sizeof (der);
+ asn1_bit_der (str, bit_len, der, &der_len);
+- if (der_len != 5 || memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0)
++ if (der_len != 5 || grub_memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0)
+ {
+ grub_printf ("asn1_bit_der example roundtrip\n");
+ return 1;
+@@ -197,13 +197,13 @@ test_simple (void)
+
+ /* 03 81 04 06 6e 5d c0 long form of length octets */
+
+- memcpy (der, "\x81\x04\x06\x6e\x5d\xc0", 6);
++ grub_memcpy (der, "\x81\x04\x06\x6e\x5d\xc0", 6);
+ der_len = 6;
+
+ result = asn1_get_bit_der (der, der_len, &ret_len, str, str_size, &bit_len);
+
+ if (result != ASN1_SUCCESS || ret_len != 6
+- || bit_len != 18 || memcmp (str, "\x6e\x5d\xc0", 3) != 0)
++ || bit_len != 18 || grub_memcmp (str, "\x6e\x5d\xc0", 3) != 0)
+ {
+ grub_printf ("asn1_get_bit_der example long form\n");
+ return 1;
+@@ -211,7 +211,7 @@ test_simple (void)
+
+ der_len = sizeof (der);
+ asn1_bit_der (str, bit_len, der, &der_len);
+- if (der_len != 5 || memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0)
++ if (der_len != 5 || grub_memcmp (der, "\x04\x06\x6e\x5d\xc0", 5) != 0)
+ {
+ grub_printf ("asn1_bit_der example roundtrip\n");
+ return 1;
+diff --git a/grub-core/tests/asn1/tests/Test_strings.c
b/grub-core/tests/asn1/tests/Test_strings.c
+index 65c30937f..c7c1afa1b 100644
+--- a/grub-core/tests/asn1/tests/Test_strings.c
++++ b/grub-core/tests/asn1/tests/Test_strings.c
+@@ -94,7 +94,7 @@ test_strings (void)
+ }
+ der_len = tl_len + tv[i].str_len;
+
+- if (der_len != tv[i].der_len || memcmp (tl, tv[i].der, tl_len) != 0)
++ if (der_len != tv[i].der_len || grub_memcmp (tl, tv[i].der, tl_len) !=
0)
+ {
+ grub_printf ("DER encoding differs in %u! (size: %u, expected:
%u)\n", i, der_len, tv[i].der_len);
+ return 1;
+@@ -110,7 +110,7 @@ test_strings (void)
+ return 1;
+ }
+
+- if (str_len != tv[i].str_len || memcmp (str, tv[i].str, str_len) != 0)
++ if (str_len != tv[i].str_len || grub_memcmp (str, tv[i].str, str_len)
!= 0)
+ {
+ grub_printf ("DER decoded data differ in %u! (size: %u, expected:
%u)\n", i, der_len, tv[i].str_len);
+ return 1;
+@@ -130,12 +130,12 @@ test_strings (void)
+ return 1;
+ }
+
+- if (str_len != ber[i].str_len || memcmp (b, ber[i].str, str_len) != 0)
++ if (str_len != ber[i].str_len || grub_memcmp (b, ber[i].str, str_len)
!= 0)
+ {
+ grub_printf ("BER decoded data differ in %u! (size: %u, expected:
%u)\n", i, str_len, ber[i].str_len);
+ return 1;
+ }
+- free (b);
++ grub_free (b);
+ }
+
+
+diff --git a/grub-core/tests/asn1/tests/object-id-decoding.c
b/grub-core/tests/asn1/tests/object-id-decoding.c
+index c087b46e3..91af8cde5 100644
+--- a/grub-core/tests/asn1/tests/object-id-decoding.c
++++ b/grub-core/tests/asn1/tests/object-id-decoding.c
+@@ -74,7 +74,7 @@ test_object_id_decoding (void)
+ {
+ char str[128];
+ int ret, ret_len;
+- size_t i;
++ grub_size_t i;
+
+ for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
+ {
+@@ -100,7 +100,7 @@ test_object_id_decoding (void)
+ return 1;
+ }
+
+- if (strcmp (tv[i].oid, str) != 0)
++ if (grub_strcmp (tv[i].oid, str) != 0)
+ {
+ grub_printf ("%d: strcmp iter %lu: got invalid OID: %s, expected:
%s\n",
+ __LINE__, (unsigned long) i, str, tv[i].oid);
+diff --git a/grub-core/tests/asn1/tests/object-id-encoding.c
b/grub-core/tests/asn1/tests/object-id-encoding.c
+index e3da092cc..f8f98ff17 100644
+--- a/grub-core/tests/asn1/tests/object-id-encoding.c
++++ b/grub-core/tests/asn1/tests/object-id-encoding.c
+@@ -104,7 +104,7 @@ test_object_id_encoding (void)
+ return 1;
+ }
+
+- if (der_len != tv[i].der_len || memcmp (der, tv[i].der, der_len) != 0)
++ if (der_len != tv[i].der_len || grub_memcmp (der, tv[i].der, der_len)
!= 0)
+ {
+ grub_printf ("%d: iter %lu, re-encoding of OID %s resulted to
different string (%d vs %d bytes)\n",
+ __LINE__, (unsigned long) i, tv[i].oid, der_len,
tv[i].der_len);
+diff --git a/grub-core/tests/asn1/tests/octet-string.c
b/grub-core/tests/asn1/tests/octet-string.c
+index d3a35dff8..dcf0fb808 100644
+--- a/grub-core/tests/asn1/tests/octet-string.c
++++ b/grub-core/tests/asn1/tests/octet-string.c
+@@ -116,7 +116,7 @@ test_octet_string (void)
+ int str_size = sizeof (str);
+ unsigned char *tmp = NULL;
+ int ret, ret_len, j;
+- size_t i;
++ grub_size_t i;
+
+ for (i = 0; i < sizeof (tv) / sizeof (tv[0]); i++)
+ {
+@@ -146,7 +146,7 @@ test_octet_string (void)
+ }
+
+ if (str_size != tv[i].len
+- || memcmp (tv[i].string, str, tv[i].len) != 0)
++ || grub_memcmp (tv[i].string, str, tv[i].len) != 0)
+ {
+ grub_printf ("%d: memcmp: %s: got invalid decoding\n",
+ __LINE__, tv[i].name);
+@@ -167,7 +167,7 @@ test_octet_string (void)
+ asn1_octet_der (str, str_size, der, &der_len);
+
+ if (der_len != tv[i].der_len - 1
+- || memcmp (tv[i].der_str + 1, der, tv[i].der_len - 1) != 0)
++ || grub_memcmp (tv[i].der_str + 1, der, tv[i].der_len - 1) != 0)
+ {
+ grub_printf ("encoding: %s: got invalid encoding\n", tv[i].name);
+ return 1;
+@@ -196,7 +196,7 @@ test_octet_string (void)
+ return 1;
+ }
+
+- if (str_size != tv[i].len || memcmp (tv[i].string, tmp, tv[i].len) != 0)
++ if (str_size != tv[i].len || grub_memcmp (tv[i].string, tmp, tv[i].len)
!= 0)
+ {
+ grub_printf ("%d: memcmp: %s: got invalid decoding\n", __LINE__,
tv[i].name);
+ grub_printf ("\nGot:\t\t");
+@@ -209,7 +209,7 @@ test_octet_string (void)
+ grub_printf ("\n");
+ return 1;
+ }
+- free (tmp);
++ grub_free (tmp);
+ tmp = NULL;
+
+ }
+--
+2.35.3
+
--
2.35.3
- [PATCH v19 05/33] libtasn1: replace strcat() with _asn1_str_cat(), (continued)
- [PATCH v19 05/33] libtasn1: replace strcat() with _asn1_str_cat(), Gary Lin, 2024/09/06
- [PATCH v19 02/33] libtasn1: import libtasn1-4.19.0, Gary Lin, 2024/09/06
- [PATCH v19 07/33] libtasn1: Use grub_divmod64() for division, Gary Lin, 2024/09/06
- [PATCH v19 06/33] libtasn1: adjust the header paths in libtasn1.h, Gary Lin, 2024/09/06
- [PATCH v19 08/33] libtasn1: fix the potential buffer overrun, Gary Lin, 2024/09/06
- [PATCH v19 09/33] asn1_test: include asn1_test.h only, Gary Lin, 2024/09/06
- [PATCH v19 10/33] asn1_test: rename the main functions to the test names, Gary Lin, 2024/09/06
- [PATCH v19 11/33] asn1_test: remove 'verbose' and the unnecessary printf(), Gary Lin, 2024/09/06
- [PATCH v19 12/33] asn1_test: print the error messages with grub_printf(), Gary Lin, 2024/09/06
- [PATCH v19 13/33] asn1_test: return either 0 or 1 to reflect the results, Gary Lin, 2024/09/06
- [PATCH v19 14/33] asn1_test: use the grub-specific functions and types,
Gary Lin <=
- [PATCH v19 15/33] libtasn1: compile into asn1 module, Gary Lin, 2024/09/06
- [PATCH v19 16/33] asn1_test: test module for libtasn1, Gary Lin, 2024/09/06
- [PATCH v19 17/33] libtasn1: Add the documentation, Gary Lin, 2024/09/06
- [PATCH v19 18/33] key_protector: Add key protectors framework, Gary Lin, 2024/09/06
- [PATCH v19 19/33] tss2: Add TPM2 buffer handling functions, Gary Lin, 2024/09/06
- [PATCH v19 20/33] tss2: Add TPM2 types and Marshal/Unmarshal functions, Gary Lin, 2024/09/06
- [PATCH v19 22/33] key_protector: Add TPM2 Key Protector, Gary Lin, 2024/09/06