Fix missing NULL check in MPI

This commit is contained in:
Manuel Pégourié-Gonnard 2015-04-29 17:02:01 +02:00
parent d97828e7af
commit 770b5e1e9e
5 changed files with 30 additions and 1 deletions

View file

@ -28,6 +28,8 @@ Features
errors on use of deprecated functions.
Bugfix
* mpi_size() and mpi_msb() would segfault when called on an mpi that is
initialized but not set (found by pravic).
* Fix detection of support for getrandom() on Linux (reported by syzzer) by
doing it at runtime (using uname) rather that compile time.
* Fix handling of symlinks by "make install" (found by Gaël PORTAY).

View file

@ -188,7 +188,9 @@ typedef struct
mpi;
/**
* \brief Initialize one MPI
* \brief Initialize one MPI (make internal references valid)
* This just makes it ready to be set or freed,
* but does not define a value for the MPI.
*
* \param X One MPI to initialize.
*/

View file

@ -356,6 +356,9 @@ size_t mpi_msb( const mpi *X )
{
size_t i, j;
if( X->n == 0 )
return( 0 );
for( i = X->n - 1; i > 0; i-- )
if( X->p[i] != 0 )
break;

View file

@ -1,3 +1,6 @@
Arguments with no value
mpi_null:
Base test mpi_read_write_string #1
mpi_read_write_string:10:"128":10:"128":100:0:0

View file

@ -7,6 +7,25 @@
* END_DEPENDENCIES
*/
/* BEGIN_CASE */
void mpi_null( )
{
mpi X, Y, Z;
mpi_init( &X );
mpi_init( &Y );
mpi_init( &Z );
TEST_ASSERT( mpi_get_bit( &X, 42 ) == 0 );
TEST_ASSERT( mpi_lsb( &X ) == 0 );
TEST_ASSERT( mpi_msb( &X ) == 0 );
TEST_ASSERT( mpi_size( &X ) == 0 );
exit:
mpi_free( &X );
}
/* END_CASE */
/* BEGIN_CASE */
void mpi_read_write_string( int radix_X, char *input_X, int radix_A,
char *input_A, int output_size, int result_read,