mirror of https://github.com/openssl/openssl.git
				
				
				
			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)
(cherry picked from commit 5b030ec080)
Reviewed-by: Hugo Landau <hlandau@openssl.org>
			
			
This commit is contained in:
		
							parent
							
								
									bc15591d7d
								
							
						
					
					
						commit
						a262d4ff18
					
				|  | @ -136,3 +136,7 @@ typedef struct ag_capable_st { | ||||||
|  */ |  */ | ||||||
| void ossl_prov_cache_exported_algorithms(const OSSL_ALGORITHM_CAPABLE *in, | void ossl_prov_cache_exported_algorithms(const OSSL_ALGORITHM_CAPABLE *in, | ||||||
|                                          OSSL_ALGORITHM *out); |                                          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; |         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