gpg: Fix for new SOS changes when used with Libgcrypt < 1.8.6.

* g10/free-packet.c (is_mpi_copy_broken): New.
(my_mpi_copy): Mix gcry_mpi_copy.
--

Note that in this case it is better to do a runtime check.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2020-06-09 18:16:44 +02:00
parent 96f1ed5468
commit eeb599c9e2
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 27 additions and 0 deletions

View File

@ -30,6 +30,22 @@
#include "options.h"
/* Run time check to see whether mpi_copy does not copy the flags
* properly. This was fixed in version 1.8.6. */
static int
is_mpi_copy_broken (void)
{
static char result;
if (!result)
{
result = !gcry_check_version ("1.8.6");
result |= 0x80;
}
return (result & 1);
}
/* This is mpi_copy with a fix for opaque MPIs which store a NULL
pointer. This will also be fixed in Libggcrypt 1.7.0. */
static gcry_mpi_t
@ -40,6 +56,17 @@ my_mpi_copy (gcry_mpi_t a)
&& !gcry_mpi_get_opaque (a, NULL))
return NULL;
if (is_mpi_copy_broken ())
{
int flag_user2 = a? gcry_mpi_get_flag (a, GCRYMPI_FLAG_USER2) : 0;
gcry_mpi_t b;
b = gcry_mpi_copy (a);
if (b && flag_user2)
gcry_mpi_set_flag (b, GCRYMPI_FLAG_USER2);
return b;
}
return gcry_mpi_copy (a);
}