Bignum: remove unnecessary NULL pointer checks
A null pointer dereference, or null pointer plus small offset, is a clean runtime error in most environments. So it's not particularly useful to protect against this. While at it make a null pointer check that is actually necessary more robust. Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
parent
296ea66442
commit
56a10f97ba
3 changed files with 5 additions and 12 deletions
|
@ -227,7 +227,7 @@ int mbedtls_mpi_core_read_be( mbedtls_mpi_uint *X,
|
|||
|
||||
/* Avoid calling `memcpy` with NULL source or destination argument,
|
||||
* even if buflen is 0. */
|
||||
if( buflen != 0 )
|
||||
if( buf != NULL )
|
||||
{
|
||||
Xp = (unsigned char*) X;
|
||||
memcpy( Xp + overhead, buf, buflen );
|
||||
|
|
|
@ -47,9 +47,6 @@ int mbedtls_mpi_mod_residue_setup( mbedtls_mpi_mod_residue *r,
|
|||
mbedtls_mpi_uint *p,
|
||||
size_t pn )
|
||||
{
|
||||
if( p == NULL || m == NULL || r == NULL )
|
||||
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||
|
||||
if( pn < m->n || !mbedtls_mpi_core_lt_ct( m->p, p, pn ) )
|
||||
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||
|
||||
|
@ -112,9 +109,6 @@ int mbedtls_mpi_mod_modulus_setup( mbedtls_mpi_mod_modulus *m,
|
|||
{
|
||||
int ret = 0;
|
||||
|
||||
if ( p == NULL || m == NULL )
|
||||
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||
|
||||
m->p = p;
|
||||
m->n = pn;
|
||||
m->plen = mbedtls_mpi_core_bitlen( p, pn );
|
||||
|
|
|
@ -78,9 +78,8 @@ typedef struct {
|
|||
* \param pn The number of limbs of \p p.
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p r, \p m or \p p is #NULL
|
||||
* pointer, \p pn is less than the limbs in \p m or if \p p is not
|
||||
* less than \p m.
|
||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p pn is less than the limbs
|
||||
* in \p m or if \p p is not less than \p m.
|
||||
*/
|
||||
int mbedtls_mpi_mod_residue_setup( mbedtls_mpi_mod_residue *r,
|
||||
mbedtls_mpi_mod_modulus *m,
|
||||
|
@ -119,8 +118,8 @@ void mbedtls_mpi_mod_modulus_init( mbedtls_mpi_mod_modulus *m );
|
|||
* associated with \p m (see #mbedtls_mpi_mod_rep_selector).
|
||||
*
|
||||
* \return \c 0 if successful.
|
||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p m or \p p is
|
||||
* #NULL pointer or if \p ext_rep or \p int_rep is invalid.
|
||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p ext_rep or \p int_rep is
|
||||
* invalid.
|
||||
*/
|
||||
int mbedtls_mpi_mod_modulus_setup( mbedtls_mpi_mod_modulus *m,
|
||||
mbedtls_mpi_uint *p,
|
||||
|
|
Loading…
Reference in a new issue