Skip to content

Commit db42062

Browse files
mpi_copy: make the 0 case slightly more robust
If Y was constructed through functions in this module, then Y->n == 0 iff Y->p == NULL. However we do not prevent filling mpi structures manually, and zero may be represented with n=0 and p a valid pointer. Most of the code can cope with such a representation, but for the source of mbedtls_mpi_copy, this would cause an integer underflow. Changing the test for zero from Y->p==NULL to Y->n==0 causes this case to work at no extra cost.
1 parent 7428b45 commit db42062

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/bignum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y )
199199
if( X == Y )
200200
return( 0 );
201201

202-
if( Y->p == NULL )
202+
if( Y->n == 0 )
203203
{
204204
mbedtls_mpi_free( X );
205205
return( 0 );

0 commit comments

Comments
 (0)