Skip to content

Commit

Permalink
various kdfs: Always reset buflen after clearing the buffer
Browse files Browse the repository at this point in the history
Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#17165)
  • Loading branch information
t8m committed Nov 30, 2021
1 parent 29a27cb commit d2217c8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions providers/implementations/kdfs/krb5kdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static int krb5kdf_set_membuf(unsigned char **dst, size_t *dst_len,
{
OPENSSL_clear_free(*dst, *dst_len);
*dst = NULL;
*dst_len = 0;
return OSSL_PARAM_get_octet_string(p, (void **)dst, 0, dst_len);
}

Expand Down
4 changes: 3 additions & 1 deletion providers/implementations/kdfs/pbkdf1.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,15 @@ static int kdf_pbkdf1_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;
}
Expand Down
4 changes: 3 additions & 1 deletion providers/implementations/kdfs/pbkdf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ static int pbkdf2_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;
}
Expand Down
4 changes: 3 additions & 1 deletion providers/implementations/kdfs/pkcs12kdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ static int pkcs12kdf_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;
}
Expand Down
4 changes: 3 additions & 1 deletion providers/implementations/kdfs/scrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ static int scrypt_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;
}
Expand Down
1 change: 1 addition & 0 deletions providers/implementations/kdfs/sshkdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static int sshkdf_set_membuf(unsigned char **dst, size_t *dst_len,
{
OPENSSL_clear_free(*dst, *dst_len);
*dst = NULL;
*dst_len = 0;
return OSSL_PARAM_get_octet_string(p, (void **)dst, 0, dst_len);
}

Expand Down

0 comments on commit d2217c8

Please sign in to comment.