mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	Merge pull request #4752 from mpg/fix-memleak-in-ssl-test
Fix memory leak on failure path in test code
This commit is contained in:
		
						commit
						07704c09ce
					
				@ -145,7 +145,7 @@ void dtls_srtp_key_derivation( void *p_expkey,
 | 
				
			|||||||
int ssl_check_record( mbedtls_ssl_context const *ssl,
 | 
					int ssl_check_record( mbedtls_ssl_context const *ssl,
 | 
				
			||||||
                      unsigned char const *buf, size_t len )
 | 
					                      unsigned char const *buf, size_t len )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int ret;
 | 
					    int my_ret = 0, ret_cr1, ret_cr2;
 | 
				
			||||||
    unsigned char *tmp_buf;
 | 
					    unsigned char *tmp_buf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Record checking may modify the input buffer,
 | 
					    /* Record checking may modify the input buffer,
 | 
				
			||||||
@ -155,22 +155,21 @@ int ssl_check_record( mbedtls_ssl_context const *ssl,
 | 
				
			|||||||
        return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
 | 
					        return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
 | 
				
			||||||
    memcpy( tmp_buf, buf, len );
 | 
					    memcpy( tmp_buf, buf, len );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = mbedtls_ssl_check_record( ssl, tmp_buf, len );
 | 
					    ret_cr1 = mbedtls_ssl_check_record( ssl, tmp_buf, len );
 | 
				
			||||||
    if( ret != MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE )
 | 
					    if( ret_cr1 != MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int ret_repeated;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /* Test-only: Make sure that mbedtls_ssl_check_record()
 | 
					        /* Test-only: Make sure that mbedtls_ssl_check_record()
 | 
				
			||||||
         *            doesn't alter state. */
 | 
					         *            doesn't alter state. */
 | 
				
			||||||
        memcpy( tmp_buf, buf, len ); /* Restore buffer */
 | 
					        memcpy( tmp_buf, buf, len ); /* Restore buffer */
 | 
				
			||||||
        ret_repeated = mbedtls_ssl_check_record( ssl, tmp_buf, len );
 | 
					        ret_cr2 = mbedtls_ssl_check_record( ssl, tmp_buf, len );
 | 
				
			||||||
        if( ret != ret_repeated )
 | 
					        if( ret_cr2 != ret_cr1 )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            mbedtls_printf( "mbedtls_ssl_check_record() returned inconsistent results.\n" );
 | 
					            mbedtls_printf( "mbedtls_ssl_check_record() returned inconsistent results.\n" );
 | 
				
			||||||
            return( -1 );
 | 
					            my_ret = -1;
 | 
				
			||||||
 | 
					            goto cleanup;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        switch( ret )
 | 
					        switch( ret_cr1 )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            case 0:
 | 
					            case 0:
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
@ -191,16 +190,18 @@ int ssl_check_record( mbedtls_ssl_context const *ssl,
 | 
				
			|||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
                mbedtls_printf( "mbedtls_ssl_check_record() failed fatally with -%#04x.\n", (unsigned int) -ret );
 | 
					                mbedtls_printf( "mbedtls_ssl_check_record() failed fatally with -%#04x.\n", (unsigned int) -ret_cr1 );
 | 
				
			||||||
                return( -1 );
 | 
					                my_ret = -1;
 | 
				
			||||||
 | 
					                goto cleanup;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Regardless of the outcome, forward the record to the stack. */
 | 
					        /* Regardless of the outcome, forward the record to the stack. */
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cleanup:
 | 
				
			||||||
    mbedtls_free( tmp_buf );
 | 
					    mbedtls_free( tmp_buf );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( 0 );
 | 
					    return( my_ret );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int recv_cb( void *ctx, unsigned char *buf, size_t len )
 | 
					int recv_cb( void *ctx, unsigned char *buf, size_t len )
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user