mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-10-30 19:20:40 -04:00 
			
		
		
		
	better handling of failed calloc
This commit is contained in:
		
							parent
							
								
									57863ad7ed
								
							
						
					
					
						commit
						2cfa5072ed
					
				| @ -173,12 +173,6 @@ int mbedtls_cmac_setkey( mbedtls_cmac_context *ctx, | |||||||
|     if( cipher_info == NULL ) |     if( cipher_info == NULL ) | ||||||
|         return( MBEDTLS_ERR_CMAC_BAD_INPUT ); |         return( MBEDTLS_ERR_CMAC_BAD_INPUT ); | ||||||
| 
 | 
 | ||||||
|     ctx->K1 = mbedtls_calloc( cipher_info->block_size, sizeof( unsigned char ) ); |  | ||||||
|     ctx->K2 = mbedtls_calloc( cipher_info->block_size, sizeof( unsigned char ) ); |  | ||||||
| 
 |  | ||||||
|     if(ctx->K1 == NULL || ctx->K2 == NULL ) |  | ||||||
|         return MBEDTLS_ERR_CMAC_ALLOC_FAILED; |  | ||||||
| 
 |  | ||||||
|     mbedtls_cipher_free( &ctx->cipher_ctx ); |     mbedtls_cipher_free( &ctx->cipher_ctx ); | ||||||
| 
 | 
 | ||||||
|     if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) |     if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) | ||||||
| @ -190,6 +184,16 @@ int mbedtls_cmac_setkey( mbedtls_cmac_context *ctx, | |||||||
|         return( ret ); |         return( ret ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     ctx->K1 = mbedtls_calloc( cipher_info->block_size, sizeof( unsigned char ) ); | ||||||
|  |     ctx->K2 = mbedtls_calloc( cipher_info->block_size, sizeof( unsigned char ) ); | ||||||
|  | 
 | ||||||
|  |     if( ctx->K1 == NULL || ctx->K2 == NULL ) | ||||||
|  |     { | ||||||
|  |         mbedtls_free(ctx->K1); | ||||||
|  |         mbedtls_free(ctx->K2); | ||||||
|  |         return( MBEDTLS_ERR_CMAC_ALLOC_FAILED ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     return( cmac_generate_subkeys( ctx ) ); |     return( cmac_generate_subkeys( ctx ) ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Brian Murray
						Brian Murray