mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	psa_export_key: for raw-byte keys, zero the end of the output buffer
Skip all writing to the target buffer if its size is 0, since in this case the pointer might be invalid and this would cause the calls to memcpy and memset to have undefined behavior.
This commit is contained in:
		
							parent
							
								
									188c71e382
								
							
						
					
					
						commit
						52b9018cf7
					
				@ -864,8 +864,12 @@ static  psa_status_t psa_internal_export_key( psa_key_slot_t key,
 | 
			
		||||
    {
 | 
			
		||||
        if( slot->data.raw.bytes > data_size )
 | 
			
		||||
            return( PSA_ERROR_BUFFER_TOO_SMALL );
 | 
			
		||||
        if( slot->data.raw.bytes != 0 )
 | 
			
		||||
        if( data_size != 0 )
 | 
			
		||||
        {
 | 
			
		||||
            memcpy( data, slot->data.raw.data, slot->data.raw.bytes );
 | 
			
		||||
            memset( data + slot->data.raw.bytes, 0,
 | 
			
		||||
                    data_size - slot->data.raw.bytes );
 | 
			
		||||
        }
 | 
			
		||||
        *data_length = slot->data.raw.bytes;
 | 
			
		||||
        return( PSA_SUCCESS );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user