mirror of
https://github.com/openssl/openssl.git
synced 2024-11-27 05:21:51 +08:00
prov: add a safe memdup function for context cloning
Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/17572)
This commit is contained in:
parent
a841d450a4
commit
5b030ec080
@ -136,3 +136,7 @@ typedef struct ag_capable_st {
|
||||
*/
|
||||
void ossl_prov_cache_exported_algorithms(const OSSL_ALGORITHM_CAPABLE *in,
|
||||
OSSL_ALGORITHM *out);
|
||||
|
||||
/* Duplicate a lump of memory safely */
|
||||
int ossl_prov_memdup(const void *src, size_t src_len,
|
||||
unsigned char **dest, size_t *dest_len);
|
||||
|
@ -351,3 +351,20 @@ void ossl_prov_cache_exported_algorithms(const OSSL_ALGORITHM_CAPABLE *in,
|
||||
out[j++] = in[i].alg;
|
||||
}
|
||||
}
|
||||
|
||||
/* Duplicate a lump of memory safely */
|
||||
int ossl_prov_memdup(const void *src, size_t src_len,
|
||||
unsigned char **dest, size_t *dest_len)
|
||||
{
|
||||
if (src != NULL) {
|
||||
if ((*dest = OPENSSL_memdup(src, src_len)) == NULL) {
|
||||
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
*dest_len = src_len;
|
||||
} else {
|
||||
*dest = NULL;
|
||||
*dest_len = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user