Params API: {utf8,octet}_ptr need to know the data size
authorRichard Levitte <levitte@openssl.org>
Tue, 9 Apr 2019 06:31:09 +0000 (08:31 +0200)
committerRichard Levitte <levitte@openssl.org>
Tue, 9 Apr 2019 12:10:23 +0000 (14:10 +0200)
When the purpose is to pass parameters to a setter function, that
setter function needs to know the size of the data passed.  This
remains true for the pointer data types as well.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8703)

crypto/params.c
doc/man3/OSSL_PARAM_TYPE.pod
include/openssl/params.h
test/params_api_test.c
test/params_test.c

index 8b75e0483980c26d6a25a2555f34e2af6f7af5cd..bdb1fa92d93a7f26fc49774d42e1a13d9335e9ad 100644 (file)
@@ -580,15 +580,15 @@ int OSSL_PARAM_set_octet_ptr(const OSSL_PARAM *p, const void *val,
 }
 
 OSSL_PARAM OSSL_PARAM_construct_utf8_ptr(const char *key, char **buf,
-                                         size_t *rsize)
+                                         size_t bsize, size_t *rsize)
 {
-    return ossl_param_construct(key, OSSL_PARAM_UTF8_PTR, buf, 0, rsize);
+    return ossl_param_construct(key, OSSL_PARAM_UTF8_PTR, buf, bsize, rsize);
 }
 
 OSSL_PARAM OSSL_PARAM_construct_octet_ptr(const char *key, void **buf,
-                                          size_t *rsize)
+                                          size_t bsize, size_t *rsize)
 {
-    return ossl_param_construct(key, OSSL_PARAM_OCTET_PTR, buf, 0, rsize);
+    return ossl_param_construct(key, OSSL_PARAM_OCTET_PTR, buf, bsize, rsize);
 }
 
 OSSL_PARAM OSSL_PARAM_construct_end(void)
index dd887f3089596c61d0be8cd70330cbe7a86c9975..4585f25acd5aee695a7ddf2e66510f95eeec13eb 100644 (file)
@@ -44,9 +44,9 @@ OSSL_PARAM_set_octet_ptr
  OSSL_PARAM OSSL_PARAM_construct_octet_string(const char *key, void *buf,
                                               size_t bsize, size_t *rsize);
  OSSL_PARAM OSSL_PARAM_construct_utf8_ptr(const char *key, char **buf,
-                                          size_t *rsize);
+                                          size_t bsize, size_t *rsize);
  OSSL_PARAM OSSL_PARAM_construct_octet_ptr(const char *key, void **buf,
-                                           size_t *rsize);
+                                           size_t bsize, size_t *rsize);
  OSSL_PARAM OSSL_PARAM_construct_end(void);
 
  OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *array, const char *key);
@@ -173,13 +173,13 @@ size B<rsize> is created.
 
 OSSL_PARAM_construct_utf8_ptr() is a function that constructes a UTF string
 pointer OSSL_PARAM structure.
-A parameter with name B<key>, storage pointer B<*buf> and return size B<rsize>
-is created.
+A parameter with name B<key>, storage pointer B<*buf>, size B<bsize> and
+return size B<rsize> is created.
 
 OSSL_PARAM_construct_octet_ptr() is a function that constructes an OCTET string
 pointer OSSL_PARAM structure.
-A parameter with name B<key>, storage pointer B<*buf> and return size B<rsize>
-is created.
+A parameter with name B<key>, storage pointer B<*buf>, size B<bsize> and
+return size B<rsize> is created.
 
 OSSL_PARAM_construct_end() is a function that constructs the terminating
 OSSL_PARAM structure.
@@ -254,6 +254,13 @@ Integral types will be widened and sign extended as required.
 Apart from that, the functions must be used appropriately for the
 expected type of the parameter.
 
+For OSSL_PARAM_get_utf8_ptr() and OSSL_PARAM_get_octet_ptr(), B<bsize>
+is not relevant if the purpose is to send the B<OSSL_PARAM> array to a
+I<responder>, i.e. to get parameter data back.
+In that case, B<bsize> can safely be given zero.
+See L<OSSL_PARAM(3)/DESCRIPTION> for further information on the
+possible purposes.
+
 =head1 EXAMPLES
 
 Reusing the examples from L<OSSL_PARAM(3)> to just show how
index cf9ffa8c7a174a20454d6c390912638b1296d942..aea24bb2ff80b76489335512593ba509a4d3bbf8 100644 (file)
@@ -132,11 +132,11 @@ OSSL_PARAM OSSL_PARAM_construct_double(const char *key, double *buf,
 OSSL_PARAM OSSL_PARAM_construct_utf8_string(const char *key, char *buf,
                                             size_t bsize, size_t *rsize);
 OSSL_PARAM OSSL_PARAM_construct_utf8_ptr(const char *key, char **buf,
-                                         size_t *rsize);
+                                         size_t bsize, size_t *rsize);
 OSSL_PARAM OSSL_PARAM_construct_octet_string(const char *key, void *buf,
                                              size_t bsize, size_t *rsize);
 OSSL_PARAM OSSL_PARAM_construct_octet_ptr(const char *key, void **buf,
-                                          size_t *rsize);
+                                          size_t bsize, size_t *rsize);
 OSSL_PARAM OSSL_PARAM_construct_end(void);
 
 int OSSL_PARAM_get_int(const OSSL_PARAM *p, int *val);
index a3d23377459eea04848460864cd963ef3bec60a7..df708da7e1a1caa7f771633701bead092206b30d 100644 (file)
@@ -475,8 +475,8 @@ static int test_param_construct(void)
                                                    &sz);
     params[n++] = OSSL_PARAM_construct_octet_string("octstr", buf, sizeof(buf),
                                                     &sz);
-    params[n++] = OSSL_PARAM_construct_utf8_ptr("utf8ptr", &bufp, &sz);
-    params[n++] = OSSL_PARAM_construct_octet_ptr("octptr", &vp, &sz);
+    params[n++] = OSSL_PARAM_construct_utf8_ptr("utf8ptr", &bufp, 0, &sz);
+    params[n++] = OSSL_PARAM_construct_octet_ptr("octptr", &vp, 0, &sz);
     params[n] = OSSL_PARAM_construct_end();
 
     /* Search failure */
index 8d456bbbde28b221d1c681d6b335a902d942c3cc..a128d8cdda204ca006b76fd05473d2d984466b95 100644 (file)
@@ -400,7 +400,7 @@ static OSSL_PARAM *construct_api_params(void)
     params[n++] = OSSL_PARAM_construct_utf8_string("p5", app_p5,
                                                    sizeof(app_p5), &app_p5_l);
     params[n++] = OSSL_PARAM_construct_utf8_ptr("p6", (char **)&app_p6,
-                                                &app_p6_l);
+                                                sizeof(app_p6), &app_p6_l);
     params[n++] = OSSL_PARAM_construct_octet_string("foo", &foo, sizeof(foo),
                                                     &foo_l);
     params[n++] = OSSL_PARAM_construct_end();