Params from text to allow zero length value fields
@@ -107,6 +107,7 @@ static int construct_from_text(OSSL_PARAM *to, const OSSL_PARAM *paramdef,
if (buf == NULL)
return 0;
+ if (buf_n > 0) {
switch (paramdef->data_type) {
case OSSL_PARAM_INTEGER:
case OSSL_PARAM_UNSIGNED_INTEGER:
@@ -146,10 +147,10 @@ static int construct_from_text(OSSL_PARAM *to, const OSSL_PARAM *paramdef,
return 0;
} else {
memcpy(buf, value, buf_n);
-
}
break;
}
+ }
*to = *paramdef;
to->data = buf;
@@ -209,7 +210,7 @@ int OSSL_PARAM_allocate_from_text(OSSL_PARAM *to,
&paramdef, &ishex, &buf_n, &tmpbn))
return 0;
- if ((buf = OPENSSL_malloc(buf_n)) == NULL) {
+ if ((buf = OPENSSL_zalloc(buf_n > 0 ? buf_n : 1)) == NULL) {
CRYPTOerr(0, ERR_R_MALLOC_FAILURE);
return 0;
}
@@ -217,5 +218,7 @@ int OSSL_PARAM_allocate_from_text(OSSL_PARAM *to,
ok = construct_from_text(to, paramdef, value, value_n, ishex,
buf, buf_n, tmpbn);
BN_free(tmpbn);
+ if (!ok)
+ OPENSSL_free(buf);
return ok;
}
