Error with gcry_mpi_release with opaque value.

Werner Koch wk at gnupg.org
Thu Jun 28 09:08:55 CEST 2018


Hello!

On Sun, 24 Jun 2018 10:53, stefbon at gmail.com said:

> buffer=malloc(len);
> if (buffer) {
>  memcpy(buffer, from somewhere, size);

SIZE <= LEN ?

>  mp->lib.mpi=gcry_mpi_set_opaque(NULL, (void *) buffer, (8 * len));
> }
>
> And releasing this with gcry_mpi_release program crashes.

Either you free BUFFER which you may not do because gcry_mpi_set_opaque
takes ownership of BUFFER or, more likely, you have not setup memory
allocation functions which map to standard malloc.  Libgcrypt uses its
own allocation functions and uses gcry_free to release them.  The
rationale for the own allocation fucntions is that they allow to
distinguish between standard and secure memory.

Either use

  buffer = gcry_malloc (len);

or 

  mp->lib.mpi = gcry_mpi_set_opaque_copy (NULL, from_somewhere, 8*len);


Salam-Shalom,

   Werner

-- 
#  Please read:  Daniel Ellsberg - The Doomsday Machine  #
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 227 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gcrypt-devel/attachments/20180628/049073c6/attachment.sig>


More information about the Gcrypt-devel mailing list