From: Nikos Mavrogiannopoulos Date: Mon, 30 Dec 2002 10:04:47 +0000 (+0000) Subject: Added a test for null (zero) integers in MPI scanning. X-Git-Tag: gnutls_0_8_0~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6859507a13327ceaa4e65e4eaf75ba89fc705355;p=thirdparty%2Fgnutls.git Added a test for null (zero) integers in MPI scanning. --- diff --git a/lib/gnutls_mpi.c b/lib/gnutls_mpi.c index 2dcdc3a2dc..1b27f172fa 100644 --- a/lib/gnutls_mpi.c +++ b/lib/gnutls_mpi.c @@ -36,12 +36,38 @@ void _gnutls_mpi_release( GNUTLS_MPI* x) { *x=NULL; } +/* returns zero on success + */ int _gnutls_mpi_scan( GNUTLS_MPI *ret_mpi, const opaque *buffer, size_t *nbytes ) { - return gcry_mpi_scan( ret_mpi, GCRYMPI_FMT_USG, buffer, nbytes); + int ret; + + ret = gcry_mpi_scan( ret_mpi, GCRYMPI_FMT_USG, buffer, nbytes); + if (ret) return ret; + + /* MPIs with 0 bits are illegal + */ + if (_gnutls_mpi_get_nbits( *ret_mpi) == 0) { + _gnutls_mpi_release( ret_mpi); + return 1; + } + + return 0; } int _gnutls_mpi_scan_pgp( GNUTLS_MPI *ret_mpi, const opaque *buffer, size_t *nbytes ) { - return gcry_mpi_scan( ret_mpi, GCRYMPI_FMT_PGP, buffer, nbytes); +int ret; + ret = gcry_mpi_scan( ret_mpi, GCRYMPI_FMT_PGP, buffer, nbytes); + + if (ret) return ret; + + /* MPIs with 0 bits are illegal + */ + if (_gnutls_mpi_get_nbits( *ret_mpi) == 0) { + _gnutls_mpi_release( ret_mpi); + return 1; + } + + return 0; } int _gnutls_mpi_print( opaque *buffer, size_t *nbytes, const GNUTLS_MPI a ) {