From: Simon Josefsson Date: Mon, 30 Oct 2006 12:33:23 +0000 (+0000) Subject: (gnutls_openpgp_key_get_name): Make SIZEOF_BUF contain actual/required X-Git-Tag: gnutls_1_5_4~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ec4c83502a8d7ffb4b1f54b28db6f38bb01fedfc;p=thirdparty%2Fgnutls.git (gnutls_openpgp_key_get_name): Make SIZEOF_BUF contain actual/required buffer size on return. Suggested by ludovic.courtes@laas.fr (Ludovic Courtès). --- diff --git a/libextra/openpgp/pgp.c b/libextra/openpgp/pgp.c index 0821a5ef88..c1aac52d5c 100644 --- a/libextra/openpgp/pgp.c +++ b/libextra/openpgp/pgp.c @@ -279,7 +279,8 @@ _gnutls_openpgp_count_key_names (gnutls_openpgp_key_t key) * @key: the structure that contains the OpenPGP public key. * @idx: the index of the ID to extract * @buf: a pointer to a structure to hold the name - * @sizeof_buf: holds the size of 'buf' + * @sizeof_buf: holds the maximum size of @buf, on return hold the + * actual/required size of @buf. * * Extracts the userID from the parsed OpenPGP key. * @@ -338,10 +339,9 @@ gnutls_openpgp_key_get_name (gnutls_openpgp_key_t key, goto leave; } - size = uid->len < *sizeof_buf ? uid->len : *sizeof_buf - 1; - memcpy (buf, uid->name, size); - - buf[size] = '\0'; /* make sure it's a string */ + memcpy (buf, uid->name, uid->len); + buf[uid->len] = '\0'; /* make sure it's a string */ + *sizeof_buf = uid->len + 1; if (uid->is_revoked) {