mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge pull request #346 from gilles-peskine-arm/mpi_copy_shrink
Improve robustness and testing of mbedtls_mpi_copy
This commit is contained in:
@ -158,9 +158,10 @@ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs )
|
||||
if( nblimbs > MBEDTLS_MPI_MAX_LIMBS )
|
||||
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
|
||||
|
||||
/* Actually resize up in this case */
|
||||
/* Actually resize up if there are currently fewer than nblimbs limbs. */
|
||||
if( X->n <= nblimbs )
|
||||
return( mbedtls_mpi_grow( X, nblimbs ) );
|
||||
/* After this point, then X->n > nblimbs and in particular X->n > 0. */
|
||||
|
||||
for( i = X->n - 1; i > 0; i-- )
|
||||
if( X->p[i] != 0 )
|
||||
@ -199,7 +200,7 @@ int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y )
|
||||
if( X == Y )
|
||||
return( 0 );
|
||||
|
||||
if( Y->p == NULL )
|
||||
if( Y->n == 0 )
|
||||
{
|
||||
mbedtls_mpi_free( X );
|
||||
return( 0 );
|
||||
|
Reference in New Issue
Block a user