]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add tests for EVP_PKEY_get_utf8_string_param(), both positive and negative
authorRichard Levitte <levitte@openssl.org>
Tue, 17 Aug 2021 12:32:35 +0000 (14:32 +0200)
committerRichard Levitte <levitte@openssl.org>
Wed, 18 Aug 2021 15:05:57 +0000 (17:05 +0200)
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16334)

test/evp_pkey_provided_test.c

index f075f40b0c1850c691c06923624daa6c1c4a8882..593f7090ebdd6dfc24380e7b367ba09d2a582d63 100644 (file)
@@ -526,6 +526,37 @@ static int test_fromdata_dh_named_group(void)
                                         fromdata_params)))
         goto err;
 
+    /*
+     * A few extra checks of EVP_PKEY_get_utf8_string_param() to see that
+     * it behaves as expected with regards to string length and terminating
+     * NUL byte.
+     */
+    if (!TEST_true(EVP_PKEY_get_utf8_string_param(pk,
+                                                  OSSL_PKEY_PARAM_GROUP_NAME,
+                                                  NULL, sizeof(name_out),
+                                                  &len))
+        || !TEST_size_t_eq(len, sizeof(group_name) - 1)
+        /* Just enough space to hold the group name and a terminating NUL */
+        || !TEST_true(EVP_PKEY_get_utf8_string_param(pk,
+                                                     OSSL_PKEY_PARAM_GROUP_NAME,
+                                                     name_out,
+                                                     sizeof(group_name),
+                                                     &len))
+        || !TEST_size_t_eq(len, sizeof(group_name) - 1)
+        /* Too small buffer to hold the terminating NUL byte */
+        || !TEST_false(EVP_PKEY_get_utf8_string_param(pk,
+                                                      OSSL_PKEY_PARAM_GROUP_NAME,
+                                                      name_out,
+                                                      sizeof(group_name) - 1,
+                                                      &len))
+        /* Too small buffer to hold the whole group name, even! */
+        || !TEST_false(EVP_PKEY_get_utf8_string_param(pk,
+                                                      OSSL_PKEY_PARAM_GROUP_NAME,
+                                                      name_out,
+                                                      sizeof(group_name) - 2,
+                                                      &len)))
+        goto err;
+
     while (dup_pk == NULL) {
         ret = 0;
         if (!TEST_int_eq(EVP_PKEY_get_bits(pk), 2048)