[git] GPGME - branch, master, updated. gpgme-1.3.2-17-ge11e7fc

by Werner Koch cvs at cvs.gnupg.org
Thu Oct 11 18:28:33 CEST 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, master has been updated
       via  e11e7fc5586613525035c3358e15ae24accb96ea (commit)
       via  aa30b47aa010bf46876f2335e288f8bd8718e396 (commit)
       via  3f1329e1c9b99b1632cc4c4eec2e4399676fd93d (commit)
       via  c28ebca9f2e21344d68e9fdcec60553f225c2e54 (commit)
      from  3d69b51f7f083193db28f364da4590c33b5e44e6 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e11e7fc5586613525035c3358e15ae24accb96ea
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Oct 11 17:02:50 2012 +0200

    gpgme-tool: Use membuf functions to build up strings.
    
    * src/gpgme-tool.c (clear_membuf, init_membuf, put_membuf)
    (put_membuf_str, get_membuf, peek_membuf): Add membuf functions.
    Take from GnuPG master's common/membuf.[ch] and patch for our use.
    (result_xml_escape): Rewrite using new functions.
    --
    
    First counting, then allocating, and finally copying data is prone to
    errors.  We better use the membuf functions which make it much easier.

diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c
index 057e428..eb1fbb8 100644
--- a/src/gpgme-tool.c
+++ b/src/gpgme-tool.c
@@ -475,6 +475,148 @@ argp_parse (const struct argp *argp, int argc,
 #endif
 
 
+/* MEMBUF */
+
+/* A simple implementation of a dynamic buffer.  Use init_membuf() to
+   create a buffer, put_membuf to append bytes and get_membuf to
+   release and return the buffer.  Allocation errors are detected but
+   only returned at the final get_membuf(), this helps not to clutter
+   the code with out-of-core checks.  */
+
+/* The definition of the structure is private, we only need it here,
+   so it can be allocated on the stack. */
+struct private_membuf_s
+{
+  size_t len;
+  size_t size;
+  char *buf;
+  int out_of_core;
+};
+
+typedef struct private_membuf_s membuf_t;
+
+/* Return the current length of the membuf.  */
+#define get_membuf_len(a)  ((a)->len)
+#define is_membuf_ready(a) ((a)->buf || (a)->out_of_core)
+#define MEMBUF_ZERO        { 0, 0, NULL, 0}
+
+
+static void
+init_membuf (membuf_t *mb, int initiallen)
+{
+  mb->len = 0;
+  mb->size = initiallen;
+  mb->out_of_core = 0;
+  mb->buf = malloc (initiallen);
+  if (!mb->buf)
+    mb->out_of_core = errno;
+}
+
+
+/* Shift the the content of the membuf MB by AMOUNT bytes.  The next
+   operation will then behave as if AMOUNT bytes had not been put into
+   the buffer.  If AMOUNT is greater than the actual accumulated
+   bytes, the membuf is basically reset to its initial state.  */
+#if 0 /* Not yet used.  */
+static void
+clear_membuf (membuf_t *mb, size_t amount)
+{
+  /* No need to clear if we are already out of core.  */
+  if (mb->out_of_core)
+    return;
+  if (amount >= mb->len)
+    mb->len = 0;
+  else
+    {
+      mb->len -= amount;
+      memmove (mb->buf, mb->buf+amount, mb->len);
+    }
+}
+#endif /* unused */
+
+static void
+put_membuf (membuf_t *mb, const void *buf, size_t len)
+{
+  if (mb->out_of_core || !len)
+    return;
+
+  if (mb->len + len >= mb->size)
+    {
+      char *p;
+
+      mb->size += len + 1024;
+      p = realloc (mb->buf, mb->size);
+      if (!p)
+        {
+          mb->out_of_core = errno ? errno : ENOMEM;
+          return;
+        }
+      mb->buf = p;
+    }
+  memcpy (mb->buf + mb->len, buf, len);
+  mb->len += len;
+}
+
+
+#if 0 /* Not yet used.  */
+static void
+put_membuf_str (membuf_t *mb, const char *string)
+{
+  put_membuf (mb, string, strlen (string));
+}
+#endif /* unused */
+
+
+static void *
+get_membuf (membuf_t *mb, size_t *len)
+{
+  char *p;
+
+  if (mb->out_of_core)
+    {
+      if (mb->buf)
+        {
+          free (mb->buf);
+          mb->buf = NULL;
+        }
+      gpg_err_set_errno (mb->out_of_core);
+      return NULL;
+    }
+
+  p = mb->buf;
+  if (len)
+    *len = mb->len;
+  mb->buf = NULL;
+  mb->out_of_core = ENOMEM; /* hack to make sure it won't get reused. */
+  return p;
+}
+
+
+/* Peek at the membuf MB.  On success a pointer to the buffer is
+   returned which is valid until the next operation on MB.  If LEN is
+   not NULL the current LEN of the buffer is stored there.  On error
+   NULL is returned and ERRNO is set.  */
+#if 0 /* Not yet used.  */
+static const void *
+peek_membuf (membuf_t *mb, size_t *len)
+{
+  const char *p;
+
+  if (mb->out_of_core)
+    {
+      gpg_err_set_errno (mb->out_of_core);
+      return NULL;
+    }
+
+  p = mb->buf;
+  if (len)
+    *len = mb->len;
+  return p;
+}
+#endif /* unused */
+
+
+
 /* SUPPORT.  */
 FILE *log_stream;
 char *program_name = "gpgme-tool";
@@ -658,7 +800,8 @@ result_xml_tag_start (struct result_xml_state *state, char *name, ...)
   return 0;
 }
 
-const char *
+/* Return a constant string with an XML entity for C.  */
+static const char *
 result_xml_escape_replacement(char c)
 {
   switch (c)
@@ -674,48 +817,32 @@ result_xml_escape_replacement(char c)
     }
 }
 
-gpg_error_t
+/* Escape DATA by replacing certain characters with their XML
+   entities.  The result is stored in a newly allocated buffer which
+   address will be stored at BUF.   Returns 0 on success. */
+static gpg_error_t
 result_xml_escape (const char *data, char **buf)
 {
-  int data_len, i, j = 1;
+  int data_len, i;
   const char *r;
-	char *b;
+  membuf_t mb;
 
+  init_membuf (&mb, 128);
   data_len = strlen (data);
   for (i = 0; i < data_len; i++)
     {
-      r = result_xml_escape_replacement(data[i]);
+      r = result_xml_escape_replacement (data[i]);
       if (r)
-        j += strlen (r);
+        put_membuf (&mb, r, strlen (r));
       else
-        j += 1;
+        put_membuf (&mb, data+i, 1);
     }
-
-  b = (char *) malloc (j);
-  if (! b)
-		return gpg_error_from_syserror ();
-
-  j = 0;
-  for (i = 0; i < data_len; i++)
-    {
-      r = result_xml_escape_replacement(data[i]);
-      if (r)
-        {
-          strcpy (b + j, r);
-          j += strlen (r);
-        }
-      else
-        {
-          b[j] = data[i];
-          j += 1;
-        }
-    }
-  b[j] = 0;
-	*buf = b;
-
-  return 0;
+  put_membuf (&mb, "", 1);
+  *buf = get_membuf (&mb, NULL);
+  return *buf? 0 : gpg_error_from_syserror ();
 }
 
+
 gpg_error_t
 result_xml_tag_data (struct result_xml_state *state, const char *data)
 {
@@ -734,7 +861,7 @@ result_xml_tag_data (struct result_xml_state *state, const char *data)
     (*cb) (hook, ">", 1);
   state->had_data[state->next_tag - 1] = 2;
 
-  err = result_xml_escape(data, &buf);
+  err = result_xml_escape (data, &buf);
   if (err)
     return err;
 

commit aa30b47aa010bf46876f2335e288f8bd8718e396
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Oct 11 16:54:58 2012 +0200

    gpgme-tool: Change license from LPGLv2+ to GPLv3+
    
    * src/gpgme-tool.c: Change license notice.
    --
    
    gpgme-tool.c is a standalone program, thus it makes no sense to keep
    it under the LGPL.  We already had the manual under GPLv3+.

diff --git a/AUTHORS b/AUTHORS
index 707c106..53857b4 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -3,7 +3,7 @@ Maintainer: Werner Koch <wk at gnupg.org>
 Bug reports: bug-gpgme at gnupg.org
 Security related bug reports: security at gnupg.org
 License (software): LGPLv2.1+
-License (manual): GPLv3+
+License (manual+tools): GPLv3+
 
 
 FSF <gnu at gnu.org>
diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c
index b745294..057e428 100644
--- a/src/gpgme-tool.c
+++ b/src/gpgme-tool.c
@@ -1,12 +1,13 @@
 /* gpgme-tool.c - Assuan server exposing GnuPG Made Easy operations.
-   Copyright (C) 2009, 2010 g10 Code GmbH
+   Copyright (C) 2009, 2010, 2012 g10 Code GmbH
+   Copyright (C) 2001, 2003, 2009, 2011 Free Software Foundation, Inc.
 
    This file is part of GPGME.
 
    GPGME is free software; you can redistribute it and/or modify it
-   under the terms of the GNU Lesser General Public License as
-   published by the Free Software Foundation; either version 2.1 of
-   the License, or (at your option) any later version.
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
 
    GPGME is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of

commit 3f1329e1c9b99b1632cc4c4eec2e4399676fd93d
Author: W. Trevor King <wking at tremily.us>
Date:   Sat Oct 6 11:30:21 2012 -0400

    gpgme-tool: escape special characters in output XML data (<, >, and &).
    
    [[PGP Signed Part:Undecided]]
    src/gpgme-tool.c (result_xml_escape_replacement, result_xml_escape):
    New.
    (result_xml_tag_data): Use result_xml_escape() to escape data.
    (result_add_error): Use unescaped < and >.
    --
    
    This is a general solution for generating valid XML, but the specific
    output that inspired the change was from the KEYLIST command:
    
      <uid>William Trevor King <wking at tremily.us></uid>
    
    Now the uids are properly escaped:
    
       <uid>William Trevor King &lt;wking at tremily.us&gt;</uid>
    
    Signed-off-by: W. Trevor King <wking at tremily.us>

diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c
index d37088c..b745294 100644
--- a/src/gpgme-tool.c
+++ b/src/gpgme-tool.c
@@ -657,12 +657,71 @@ result_xml_tag_start (struct result_xml_state *state, char *name, ...)
   return 0;
 }
 
+const char *
+result_xml_escape_replacement(char c)
+{
+  switch (c)
+    {
+    case '<':
+      return "&lt;";
+    case '>':
+      return "&gt;";
+    case '&':
+      return "&amp;";
+    default:
+      return NULL;
+    }
+}
+
+gpg_error_t
+result_xml_escape (const char *data, char **buf)
+{
+  int data_len, i, j = 1;
+  const char *r;
+	char *b;
+
+  data_len = strlen (data);
+  for (i = 0; i < data_len; i++)
+    {
+      r = result_xml_escape_replacement(data[i]);
+      if (r)
+        j += strlen (r);
+      else
+        j += 1;
+    }
+
+  b = (char *) malloc (j);
+  if (! b)
+		return gpg_error_from_syserror ();
+
+  j = 0;
+  for (i = 0; i < data_len; i++)
+    {
+      r = result_xml_escape_replacement(data[i]);
+      if (r)
+        {
+          strcpy (b + j, r);
+          j += strlen (r);
+        }
+      else
+        {
+          b[j] = data[i];
+          j += 1;
+        }
+    }
+  b[j] = 0;
+	*buf = b;
+
+  return 0;
+}
 
 gpg_error_t
 result_xml_tag_data (struct result_xml_state *state, const char *data)
 {
+  gpg_error_t err;
   result_xml_write_cb_t cb = state->cb;
   void *hook = state->hook;
+  char *buf = NULL;
 
   if (state->had_data[state->next_tag - 1])
     {
@@ -674,7 +733,13 @@ result_xml_tag_data (struct result_xml_state *state, const char *data)
     (*cb) (hook, ">", 1);
   state->had_data[state->next_tag - 1] = 2;
 
-  (*cb) (hook, data, strlen (data));
+  err = result_xml_escape(data, &buf);
+  if (err)
+    return err;
+
+  (*cb) (hook, buf, strlen (buf));
+
+  free (buf);
 
   return 0;
 }
@@ -714,7 +779,7 @@ result_add_error (struct result_xml_state *state, char *name, gpg_error_t err)
   char code[20];
   char msg[1024];
   snprintf (code, sizeof (code) - 1, "0x%x", err);
-  snprintf (msg, sizeof (msg) - 1, "%s &lt;%s&gt;",
+  snprintf (msg, sizeof (msg) - 1, "%s <%s>",
 	    gpg_strerror (err), gpg_strsource (err));
   result_xml_tag_start (state, name, "value", code, NULL);
   result_xml_tag_data (state, msg);

commit c28ebca9f2e21344d68e9fdcec60553f225c2e54
Author: W. Trevor King <wking at tremily.us>
Date:   Sat Oct 6 09:33:30 2012 -0400

    gpgme-tool: Fix chain_id -> chain-id in KEYLIST XML.
    
    [[PGP Signed Part:Undecided]]
    src/gpgme-tool.c (cmd_keylist): Use <chain-id> instead of <chain_id>.
    --
    All the other tags map struct attribute underscores to hyphens, so
    fixing <chain_id> follows the priciple of least surprise.
    
    Signed-off-by: W. Trevor King <wking at tremily.us>

diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c
index 23122e8..d37088c 100644
--- a/src/gpgme-tool.c
+++ b/src/gpgme-tool.c
@@ -2970,7 +2970,7 @@ cmd_keylist (assuan_context_t ctx, char *line)
 	  result_add_string (&state, "serial", key->issuer_serial);
 	  result_add_string (&state, "name", key->issuer_name);
 	  result_xml_tag_end (&state);  /* issuer */
-	  result_add_string (&state, "chain_id", key->chain_id);
+	  result_add_string (&state, "chain-id", key->chain_id);
 	  result_add_validity (&state, "owner-trust", key->owner_trust);
 	  result_xml_tag_start (&state, "subkeys", NULL);
 	  subkey = key->subkeys;

-----------------------------------------------------------------------

Summary of changes:
 AUTHORS          |    2 +-
 src/gpgme-tool.c |  207 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 201 insertions(+), 8 deletions(-)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list