diff options
author | Gilles Peskine <Gilles.Peskine@arm.com> | 2020-01-20 21:12:50 +0100 |
---|---|---|
committer | Gilles Peskine <Gilles.Peskine@arm.com> | 2020-02-03 16:21:31 +0100 |
commit | 3e9f5228c8072ce2821d2158ba8f2e561d5e5c21 (patch) | |
tree | 3275f65a78714100ae5c48e1cd79a094e39cb515 | |
parent | 8fe3b79cdb4825668c54367e2b1ed5c6f08b5144 (diff) |
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.
-rw-r--r-- | library/bignum.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/library/bignum.c b/library/bignum.c index 6713bcbf..fdf571d2 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -198,7 +198,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 ); |