]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
(gnutls_openpgp_key_get_name): Make SIZEOF_BUF contain actual/required
authorSimon Josefsson <simon@josefsson.org>
Mon, 30 Oct 2006 12:33:23 +0000 (12:33 +0000)
committerSimon Josefsson <simon@josefsson.org>
Mon, 30 Oct 2006 12:33:23 +0000 (12:33 +0000)
buffer size on return.  Suggested by ludovic.courtes@laas.fr (Ludovic
Courtès).

libextra/openpgp/pgp.c

index 0821a5ef889cd3ba0e863f70be3b65d2b5e2c7d7..c1aac52d5c1ecaddc0154d0415922e98a6876d39 100644 (file)
@@ -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)
     {