diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2002-12-30 10:04:47 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2002-12-30 10:04:47 +0000 |
commit | 6859507a13327ceaa4e65e4eaf75ba89fc705355 (patch) | |
tree | fa56588c230a8d4016f7bfacab6bc8622685717b /lib/gnutls_mpi.c | |
parent | 0f1c193342a04882a7b4b1d2377b9b03ec5ab05e (diff) | |
download | gnutls-6859507a13327ceaa4e65e4eaf75ba89fc705355.tar.gz |
Added a test for null (zero) integers in MPI scanning.
Diffstat (limited to 'lib/gnutls_mpi.c')
-rw-r--r-- | lib/gnutls_mpi.c | 30 |
1 files changed, 28 insertions, 2 deletions
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 ) { |