Allow (NULL, 0) as a representation of 0
- We don't check for NULL pointers this deep in the library
- Accessing a NULL pointer when the limb number is 0 as a mistake is the
very similar to any other out of bounds access
- We could potentially mandate at least 1 limb representation for 0 but
we either would need to enforce it or the implementation would be less
robust.
- Allowing zero limb representation - (NULL, 0) in particular - for zero
is present in the legacy interface, if we disallow it, the
compatibility code will need to deal with this (more code size and
opportunities for mistakes)
In summary, interpreting (NULL, 0) as the number zero in the core
interface is the least of the two evils.
Signed-off-by: Janos Follath <janos.follath@arm.com>
diff --git a/library/bignum_new.c b/library/bignum_new.c
index 6cbc867..04f6049 100644
--- a/library/bignum_new.c
+++ b/library/bignum_new.c
@@ -190,17 +190,13 @@
size_t nx,
size_t limbs )
{
- if( X == NULL )
- return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
-
- else if( nx < limbs )
+ if( nx < limbs )
return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL );
- else
- {
+ if( X != NULL )
memset( X, 0, nx * ciL );
- return( 0 );
- }
+
+ return( 0 );
}
/* Convert a big-endian byte array aligned to the size of mbedtls_mpi_uint