Commit 7acab0ef09 for openssl.org

commit 7acab0ef09e15c56d9159f6bc326285fc0b0e2f3
Author: Bob Beck <beck@openssl.org>
Date:   Wed Aug 5 10:19:32 2026 -0600

    Fix the tests to not pretend ASN1_STRING's are nul terminated.

    Reviewed-by: Neil Horman <nhorman@openssl.org>
    Reviewed-by: Andrew Dinh <andrewd@openssl.org>
    Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
    Merge-date: Thu Aug 27 13:52:41 2026
    Merged-from: https://github.com/openssl/openssl/pull/32178

diff --git a/test/asn1_internal_test.c b/test/asn1_internal_test.c
index 469daafc4c..9ede04cc02 100644
--- a/test/asn1_internal_test.c
+++ b/test/asn1_internal_test.c
@@ -265,12 +265,16 @@ static int test_asn1_time_conversion(char *time_string, const char *file,
                     V_ASN1_GENERALIZEDTIME)))
             goto err;
     }
-    if (!TEST_true((strcmp(time_string,
-                        (const char *)ASN1_STRING_get0_data(result))
-            == 0))) {
-        TEST_info("Expected time: %s, Got time: %s\n", time_string,
-            ASN1_STRING_get0_data(result));
-        goto err;
+    {
+        size_t rlen = ASN1_STRING_get_length(result);
+        const char *rdata = (const char *)ASN1_STRING_get0_data(result);
+
+        if (!TEST_size_t_eq(strlen(time_string), rlen)
+            || !TEST_int_eq(memcmp(time_string, rdata, rlen), 0)) {
+            TEST_info("Expected time: %s, Got time: %.*s\n", time_string,
+                (int)rlen, rdata);
+            goto err;
+        }
     }

     ret = 1;
diff --git a/test/testutil/tests.c b/test/testutil/tests.c
index ccc4727bac..44908f9779 100644
--- a/test/testutil/tests.c
+++ b/test/testutil/tests.c
@@ -533,11 +533,6 @@ int test_BN_abs_eq_word(const char *file, int line, const char *bns,
     return 0;
 }

-static const char *print_time(const ASN1_TIME *t)
-{
-    return t == NULL ? "<null>" : (const char *)ASN1_STRING_get0_data(t);
-}
-
 #define DEFINE_TIME_T_COMPARISON(opname, op)                           \
     int test_time_t_##opname(const char *file, int line,               \
         const char *s1, const char *s2,                                \
@@ -547,10 +542,21 @@ static const char *print_time(const ASN1_TIME *t)
         ASN1_TIME *at2 = ASN1_TIME_set(NULL, t2);                      \
         int r = at1 != NULL && at2 != NULL                             \
             && ASN1_TIME_compare(at1, at2) op 0;                       \
-        if (!r)                                                        \
+        if (!r) {                                                      \
+            const char *d1 = "<null>", *d2 = "<null>";                 \
+            int n1 = (int)(sizeof("<null>") - 1), n2 = n1;             \
+                                                                       \
+            if (at1 != NULL) {                                         \
+                d1 = (const char *)ASN1_STRING_get0_data(at1);         \
+                n1 = (int)ASN1_STRING_get_length(at1);                 \
+            }                                                          \
+            if (at2 != NULL) {                                         \
+                d2 = (const char *)ASN1_STRING_get0_data(at2);         \
+                n2 = (int)ASN1_STRING_get_length(at2);                 \
+            }                                                          \
             test_fail_message(NULL, file, line, "time_t", s1, s2, #op, \
-                "[%s] compared to [%s]",                               \
-                print_time(at1), print_time(at2));                     \
+                "[%.*s] compared to [%.*s]", n1, d1, n2, d2);          \
+        }                                                              \
         ASN1_STRING_free(at1);                                         \
         ASN1_STRING_free(at2);                                         \
         return r;                                                      \