1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-09 12:54:23 +01:00

gpg: Consider that gcry_mpi_get_opaque may return NULL.

* g10/seckey-cert.c (do_check): Handle a NULL opaque MPI.
--

This patch extends b2d9d10 for secret keys.  The problem is that we
changed the semantics so that opaque MPIs may be NULL with a bit
length.  This patch is not required in GnuPG 2 because we do not use
secret keys there.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2015-06-02 17:41:30 +02:00
parent b2d9d105f7
commit 8a2134b8d5
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -40,7 +40,6 @@ do_check( PKT_secret_key *sk, const char *tryagain_text, int mode,
int *canceled ) int *canceled )
{ {
gpg_error_t err; gpg_error_t err;
byte *buffer;
u16 csum=0; u16 csum=0;
int i, res; int i, res;
size_t nbytes; size_t nbytes;
@ -116,10 +115,13 @@ do_check( PKT_secret_key *sk, const char *tryagain_text, int mode,
p = gcry_mpi_get_opaque ( sk->skey[i], &ndatabits ); p = gcry_mpi_get_opaque ( sk->skey[i], &ndatabits );
ndata = (ndatabits+7)/8; ndata = (ndatabits+7)/8;
if ( ndata > 1 ) if ( ndata > 1 && p )
csumc = p[ndata-2] << 8 | p[ndata-1]; csumc = p[ndata-2] << 8 | p[ndata-1];
data = xmalloc_secure ( ndata ); data = xmalloc_secure ( ndata );
gcry_cipher_decrypt ( cipher_hd, data, ndata, p, ndata ); if (p)
gcry_cipher_decrypt ( cipher_hd, data, ndata, p, ndata );
else
memset (data, 0, ndata);
gcry_mpi_release (sk->skey[i]); sk->skey[i] = NULL ; gcry_mpi_release (sk->skey[i]); sk->skey[i] = NULL ;
p = data; p = data;
@ -197,21 +199,28 @@ do_check( PKT_secret_key *sk, const char *tryagain_text, int mode,
assert (gcry_mpi_get_flag (sk->skey[i], GCRYMPI_FLAG_OPAQUE)); assert (gcry_mpi_get_flag (sk->skey[i], GCRYMPI_FLAG_OPAQUE));
p = gcry_mpi_get_opaque (sk->skey[i], &ndatabits); p = gcry_mpi_get_opaque (sk->skey[i], &ndatabits);
ndata = (ndatabits+7)/8; if (!p)
assert (ndata >= 2); err = -1;
assert (ndata == ((p[0] << 8 | p[1]) + 7)/8 + 2); else
buffer = xmalloc_secure (ndata); {
gcry_cipher_sync (cipher_hd); byte *buffer;
buffer[0] = p[0];
buffer[1] = p[1];
gcry_cipher_decrypt (cipher_hd, buffer+2, ndata-2,
p+2, ndata-2);
csum += checksum (buffer, ndata);
gcry_mpi_release (sk->skey[i]);
err = gcry_mpi_scan( &sk->skey[i], GCRYMPI_FMT_PGP, ndata = (ndatabits+7)/8;
buffer, ndata, &ndata ); assert (ndata >= 2);
xfree (buffer); assert (ndata == ((p[0] << 8 | p[1]) + 7)/8 + 2);
buffer = xmalloc_secure (ndata);
gcry_cipher_sync (cipher_hd);
buffer[0] = p[0];
buffer[1] = p[1];
gcry_cipher_decrypt (cipher_hd, buffer+2, ndata-2,
p+2, ndata-2);
csum += checksum (buffer, ndata);
gcry_mpi_release (sk->skey[i]);
err = gcry_mpi_scan( &sk->skey[i], GCRYMPI_FMT_PGP,
buffer, ndata, &ndata );
xfree (buffer);
}
if (err) if (err)
{ {
/* Checksum was okay, but not correctly /* Checksum was okay, but not correctly