agent: Make an MD encoding function more robust.

* agent/pksign.c (do_encode_md): Use ascii_tolower and avoid
uninitalized TMP in the error case.
--

This is just in case libgcrypt ever returns an algorithm name longer
than 15 bytes.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2019-05-28 12:13:27 +02:00
parent 19415a2652
commit a2a9071746
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 12 additions and 7 deletions

View File

@ -44,16 +44,21 @@ do_encode_md (const byte * md, size_t mdlen, int algo, gcry_sexp_t * r_hash,
int i;
s = gcry_md_algo_name (algo);
if (s && strlen (s) < 16)
if (!s || strlen (s) >= 16)
{
hash = NULL;
rc = gpg_error (GPG_ERR_DIGEST_ALGO);
}
else
{
for (i=0; i < strlen (s); i++)
tmp[i] = tolower (s[i]);
for (i=0; s[i]; i++)
tmp[i] = ascii_tolower (s[i]);
tmp[i] = '\0';
}
rc = gcry_sexp_build (&hash, NULL,
"(data (flags pkcs1) (hash %s %b))",
tmp, (int)mdlen, md);
rc = gcry_sexp_build (&hash, NULL,
"(data (flags pkcs1) (hash %s %b))",
tmp, (int)mdlen, md);
}
}
else
{