diff options
author | Werner Koch <[email protected]> | 2002-09-20 07:40:01 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2002-09-20 07:40:01 +0000 |
commit | 4948f99eb44ede223344ba3fd1719f797b430ade (patch) | |
tree | 03f04d9e228e53cd7a21b2313a7d9b51f9cf1b88 /mpi | |
parent | * gpgkeys_hkp.c (handle_old_hkp_index): s/input/inp/ to avoid (diff) | |
download | gnupg-4948f99eb44ede223344ba3fd1719f797b430ade.tar.gz gnupg-4948f99eb44ede223344ba3fd1719f797b430ade.zip |
* mpicoder.c (do_get_buffer): Avoid zero length allocation.
Checked that all callers behave properly when NBYTES returns 0 as
the length of the allocated buffer.
Diffstat (limited to '')
-rw-r--r-- | mpi/ChangeLog | 6 | ||||
-rw-r--r-- | mpi/mpicoder.c | 9 |
2 files changed, 12 insertions, 3 deletions
diff --git a/mpi/ChangeLog b/mpi/ChangeLog index 238f69f31..0a2d05b64 100644 --- a/mpi/ChangeLog +++ b/mpi/ChangeLog @@ -1,3 +1,9 @@ +2002-09-20 Werner Koch <[email protected]> + + * mpicoder.c (do_get_buffer): Avoid zero length allocation. + Checked that all callers behave properly when NBYTES returns 0 as + the length of the allocated buffer. + 2002-09-10 Werner Koch <[email protected]> * mpi-bit.c (mpi_normalize): Replaced the check for protected by diff --git a/mpi/mpicoder.c b/mpi/mpicoder.c index f796888c8..8cb1538c0 100644 --- a/mpi/mpicoder.c +++ b/mpi/mpicoder.c @@ -332,12 +332,15 @@ do_get_buffer( MPI a, unsigned *nbytes, int *sign, int force_secure ) byte *p, *buffer; mpi_limb_t alimb; int i; + unsigned int n; if( sign ) *sign = a->sign; - *nbytes = a->nlimbs * BYTES_PER_MPI_LIMB; - p = buffer = force_secure || mpi_is_secure(a) ? m_alloc_secure( *nbytes) - : m_alloc( *nbytes ); + *nbytes = n = a->nlimbs * BYTES_PER_MPI_LIMB; + if (!n) + n++; /* avoid zero length allocation */ + p = buffer = force_secure || mpi_is_secure(a) ? m_alloc_secure(n) + : m_alloc(n); for(i=a->nlimbs-1; i >= 0; i-- ) { alimb = a->d[i]; |