pvkkdf: Always reset buflen after clearing the buffer
authorTomas Mraz <tomas@openssl.org>
Tue, 30 Nov 2021 10:39:52 +0000 (11:39 +0100)
committerTomas Mraz <tomas@openssl.org>
Wed, 1 Dec 2021 11:33:01 +0000 (12:33 +0100)
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17164)

providers/implementations/kdfs/pvkkdf.c

index 051c6254554b872da83996bf24580b35c35fc07d..e953911c836b2d5f810d50e5362c29d4779b10a4 100644 (file)
@@ -97,13 +97,15 @@ static int pvk_set_membuf(unsigned char **buffer, size_t *buflen,
                              const OSSL_PARAM *p)
 {
     OPENSSL_clear_free(*buffer, *buflen);
+    *buffer = NULL;
+    *buflen = 0;
+
     if (p->data_size == 0) {
         if ((*buffer = OPENSSL_malloc(1)) == NULL) {
             ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
             return 0;
         }
     } else if (p->data != NULL) {
-        *buffer = NULL;
         if (!OSSL_PARAM_get_octet_string(p, (void **)buffer, 0, buflen))
             return 0;
     }