diff options
Diffstat (limited to '')
-rw-r--r-- | mpi/ChangeLog | 9 | ||||
-rw-r--r-- | mpi/mpi-scan.c | 13 | ||||
-rw-r--r-- | mpi/mpicoder.c | 29 |
3 files changed, 40 insertions, 11 deletions
diff --git a/mpi/ChangeLog b/mpi/ChangeLog index 00e0e3e6a..775f437b4 100644 --- a/mpi/ChangeLog +++ b/mpi/ChangeLog @@ -1,3 +1,12 @@ +2005-05-06 Werner Koch <[email protected]> + + * mpi-scan.c (mpi_putbyte, mpi_getbyte): Removed. Not used. + +2005-04-21 Werner Koch <[email protected]> + + * mpicoder.c (mpi_read): Changed error detection to always return + an error while maintaining the actual number of bytes read. + 2005-03-11 Werner Koch <[email protected]> * Makefile.am (ASFLAGS): Renamed to AM_CCASFLAGS and added the diff --git a/mpi/mpi-scan.c b/mpi/mpi-scan.c index 615b9464f..fe093adea 100644 --- a/mpi/mpi-scan.c +++ b/mpi/mpi-scan.c @@ -18,8 +18,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#include <config.h> -#include <stdio.h> +#include <config.h> +#include <stdio.h> #include <stdlib.h> #include "mpi-internal.h" #include "longlong.h" @@ -31,6 +31,7 @@ * * FIXME: This code is VERY ugly! */ +#if 0 /* Code is not used */ int mpi_getbyte( MPI a, unsigned idx ) { @@ -48,14 +49,19 @@ mpi_getbyte( MPI a, unsigned idx ) } return -1; } +#endif /* Code is not used */ /**************** * Put a value at position IDX into A. idx counts from lsb to msb */ +/* FIXME: There is a problem with the long constants which should have +a LL prefix or better the macros we use at other places. */ +#if 0 /* Code is not used */ void mpi_putbyte( MPI a, unsigned idx, int xc ) { + int i, j; unsigned n; mpi_ptr_t ap; @@ -104,12 +110,13 @@ mpi_putbyte( MPI a, unsigned idx, int xc ) } abort(); /* index out of range */ } +#endif /* Code is not used */ /**************** * Count the number of zerobits at the low end of A */ -unsigned +unsigned int mpi_trailing_zeros( MPI a ) { unsigned n, count = 0; diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c index 4d4e45553..ab913861d 100644 --- a/mpi/mpicoder.c +++ b/mpi/mpicoder.c @@ -1,5 +1,5 @@ /* mpicoder.c - Coder for the external representation of MPIs - * Copyright (C) 1998, 1999 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -74,20 +74,23 @@ mpi_read(IOBUF inp, unsigned *ret_nread, int secure) #endif { int c, i, j; + unsigned int nmax = *ret_nread; unsigned nbits, nbytes, nlimbs, nread=0; mpi_limb_t a; MPI val = MPI_NULL; if( (c = iobuf_get(inp)) == -1 ) goto leave; - nread++; + if (++nread >= nmax) + goto overflow; nbits = c << 8; if( (c = iobuf_get(inp)) == -1 ) goto leave; - nread++; + if (++nread >= nmax) + goto overflow; nbits |= c; if( nbits > MAX_EXTERN_MPI_BITS ) { - log_error("mpi too large (%u bits)\n", nbits); + log_error("mpi too large for this implementation (%u bits)\n", nbits); goto leave; } @@ -108,6 +111,15 @@ mpi_read(IOBUF inp, unsigned *ret_nread, int secure) for( ; j > 0; j-- ) { a = 0; for(; i < BYTES_PER_MPI_LIMB; i++ ) { + if (nread >= nmax) { +#ifdef M_DEBUG + mpi_debug_free (val); +#else + mpi_free (val); +#endif + val = NULL; + goto overflow; + } a <<= 8; a |= iobuf_get(inp) & 0xff; nread++; } @@ -116,10 +128,11 @@ mpi_read(IOBUF inp, unsigned *ret_nread, int secure) } leave: - if( nread > *ret_nread ) - log_bug("mpi crosses packet border\n"); - else - *ret_nread = nread; + *ret_nread = nread; + return val; + overflow: + log_error ("mpi larger than indicated length (%u bytes)\n", nmax); + *ret_nread = nread; return val; } |