Merge pull request #934 from gilles-peskine-arm/mpi-0-mod-2

Fix null pointer dereference in mpi_mod_int(0, 2)
This commit is contained in:
Dave Rodgman 2022-06-29 15:02:59 +01:00 committed by GitHub
commit 5b50f38f92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Bugfix
* Fix a null pointer dereference when performing some operations on zero
represented with 0 limbs (specifically mbedtls_mpi_mod_int() dividing
by 2, and mbedtls_mpi_write_string() in base 2).

View File

@ -1785,7 +1785,7 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_
/*
* handle trivial cases
*/
if( b == 1 )
if( b == 1 || A->n == 0 )
{
*r = 0;
return( 0 );

View File

@ -67,12 +67,18 @@ mpi_read_write_string:16:"":16:"":4:0:0
Test mpi_read_write_string #9 (Empty MPI hex -> dec)
mpi_read_write_string:16:"":10:"0":4:0:0
Test mpi_read_write_string #9 (Empty MPI hex -> base 2)
mpi_read_write_string:16:"":2:"0":4:0:0
Test mpi_read_write_string #8 (Empty MPI dec -> hex)
mpi_read_write_string:10:"":16:"":4:0:0
Test mpi_read_write_string #9 (Empty MPI dec -> dec)
mpi_read_write_string:10:"":10:"0":4:0:0
Test mpi_read_write_string #9 (Empty MPI dec -> base 2)
mpi_read_write_string:16:"":2:"0":4:0:0
Test mpi_write_string #10 (Negative hex with odd number of digits)
mpi_read_write_string:16:"-1":16:"":3:0:MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL
@ -1216,9 +1222,15 @@ mbedtls_mpi_mod_int:10:"1000":2:0:0
Test mbedtls_mpi_mod_int: 0 (null) % 1
mbedtls_mpi_mod_int:16:"":1:0:0
Test mbedtls_mpi_mod_int: 0 (null) % 2
mbedtls_mpi_mod_int:16:"":2:0:0
Test mbedtls_mpi_mod_int: 0 (null) % -1
mbedtls_mpi_mod_int:16:"":-1:0:MBEDTLS_ERR_MPI_NEGATIVE_VALUE
Test mbedtls_mpi_mod_int: 0 (null) % -2
mbedtls_mpi_mod_int:16:"":-2:0:MBEDTLS_ERR_MPI_NEGATIVE_VALUE
Base test mbedtls_mpi_exp_mod #1
mbedtls_mpi_exp_mod:10:"23":10:"13":10:"29":10:"24":0