mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	Merge branch 'iotssl-519-asn1write-overflows-restricted' into development-restricted
* iotssl-519-asn1write-overflows-restricted: Fix other int casts in bounds checking Fix other occurrences of same bounds check issue Fix potential buffer overflow in asn1write
This commit is contained in:
		
						commit
						bd3639852c
					
				@ -9,6 +9,10 @@ Security
 | 
			
		||||
   * Fix potential heap corruption on Windows when
 | 
			
		||||
     mbedtls_x509_crt_parse_path() is passed a path longer than 2GB. Cannot be
 | 
			
		||||
     triggered remotely. Found by Guido Vranken, Interlworks.
 | 
			
		||||
   * Fix potential buffer overflow in some asn1_write_xxx() functions.
 | 
			
		||||
     Cannot be triggered remotely unless you create X.509 certificates based
 | 
			
		||||
     on untrusted input or write keys of untrusted origin. Found by Guido
 | 
			
		||||
     Vranken, Interlworks.
 | 
			
		||||
   * The X509 max_pathlen constraint was not enforced on intermediate
 | 
			
		||||
     certificates. Found by Nicholas Wilson, fix and tests provided by
 | 
			
		||||
     Janos Follath. #280 and #319
 | 
			
		||||
 | 
			
		||||
@ -87,7 +87,7 @@ int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
 | 
			
		||||
{
 | 
			
		||||
    size_t len = 0;
 | 
			
		||||
 | 
			
		||||
    if( *p - start < (int) size )
 | 
			
		||||
    if( *p < start || (size_t)( *p - start ) < size )
 | 
			
		||||
        return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
 | 
			
		||||
 | 
			
		||||
    len = size;
 | 
			
		||||
@ -107,7 +107,7 @@ int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start, const mbedt
 | 
			
		||||
    //
 | 
			
		||||
    len = mbedtls_mpi_size( X );
 | 
			
		||||
 | 
			
		||||
    if( *p - start < (int) len )
 | 
			
		||||
    if( *p < start || (size_t)( *p - start ) < len )
 | 
			
		||||
        return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
 | 
			
		||||
 | 
			
		||||
    (*p) -= len;
 | 
			
		||||
@ -270,7 +270,7 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
 | 
			
		||||
 | 
			
		||||
    // Calculate byte length
 | 
			
		||||
    //
 | 
			
		||||
    if( *p - start < (int) size + 1 )
 | 
			
		||||
    if( *p < start || (size_t)( *p - start ) < size + 1 )
 | 
			
		||||
        return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
 | 
			
		||||
 | 
			
		||||
    len = size + 1;
 | 
			
		||||
 | 
			
		||||
@ -96,7 +96,7 @@ static int pk_write_ec_pubkey( unsigned char **p, unsigned char *start,
 | 
			
		||||
        return( ret );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if( *p - start < (int) len )
 | 
			
		||||
    if( *p < start || (size_t)( *p - start ) < len )
 | 
			
		||||
        return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
 | 
			
		||||
 | 
			
		||||
    *p -= len;
 | 
			
		||||
 | 
			
		||||
@ -1105,11 +1105,16 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch
 | 
			
		||||
#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
 | 
			
		||||
    if( key_ex == MBEDTLS_KEY_EXCHANGE_PSK )
 | 
			
		||||
    {
 | 
			
		||||
        if( end - p < 2 + (int) psk_len )
 | 
			
		||||
        if( end - p < 2 )
 | 
			
		||||
            return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
 | 
			
		||||
 | 
			
		||||
        *(p++) = (unsigned char)( psk_len >> 8 );
 | 
			
		||||
        *(p++) = (unsigned char)( psk_len      );
 | 
			
		||||
 | 
			
		||||
        if( end < p || (size_t)( end - p ) < psk_len )
 | 
			
		||||
            return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
 | 
			
		||||
 | 
			
		||||
        memset( p, 0, psk_len );
 | 
			
		||||
        p += psk_len;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
@ -1177,11 +1182,15 @@ int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exch
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* opaque psk<0..2^16-1>; */
 | 
			
		||||
    if( end - p < 2 + (int) psk_len )
 | 
			
		||||
            return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
 | 
			
		||||
    if( end - p < 2 )
 | 
			
		||||
        return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
 | 
			
		||||
 | 
			
		||||
    *(p++) = (unsigned char)( psk_len >> 8 );
 | 
			
		||||
    *(p++) = (unsigned char)( psk_len      );
 | 
			
		||||
 | 
			
		||||
    if( end < p || (size_t)( end - p ) < psk_len )
 | 
			
		||||
        return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
 | 
			
		||||
 | 
			
		||||
    memcpy( p, psk, psk_len );
 | 
			
		||||
    p += psk_len;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -259,13 +259,16 @@ int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start,
 | 
			
		||||
    int ret;
 | 
			
		||||
    size_t len = 0;
 | 
			
		||||
 | 
			
		||||
    if( *p - start < (int) size + 1 )
 | 
			
		||||
    if( *p < start || (size_t)( *p - start ) < size )
 | 
			
		||||
        return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
 | 
			
		||||
 | 
			
		||||
    len = size;
 | 
			
		||||
    (*p) -= len;
 | 
			
		||||
    memcpy( *p, sig, len );
 | 
			
		||||
 | 
			
		||||
    if( *p - start < 1 )
 | 
			
		||||
        return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
 | 
			
		||||
 | 
			
		||||
    *--(*p) = 0;
 | 
			
		||||
    len += 1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user