[git] GnuPG - branch, master, updated. gnupg-2.1.11-164-g35f4b6a

by Werner Koch cvs at cvs.gnupg.org
Fri Apr 29 21:46:12 CEST 2016


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 "The GNU Privacy Guard".

The branch, master has been updated
       via  35f4b6aafdf1889ed1ae569af5852f47738fe993 (commit)
       via  dcad99c98616a6031ddfde313c920339e4012378 (commit)
      from  300b227cf457deb918f25bcece0d734b61ae1348 (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 35f4b6aafdf1889ed1ae569af5852f47738fe993
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Apr 29 21:45:15 2016 +0200

    common: Extend log_string to indent lines.
    
    * common/logging.c (do_logv): Add indentation when called via
    log_string.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/common/logging.c b/common/logging.c
index 7c54d72..9175b4f 100644
--- a/common/logging.c
+++ b/common/logging.c
@@ -715,7 +715,21 @@ do_logv (int level, int ignore_arg_ptr, const char *fmt, va_list arg_ptr)
   if (fmt)
     {
       if (ignore_arg_ptr)
-        es_fputs_unlocked (fmt, logstream);
+        { /* This is used by log_string and comes with the extra
+           * feature that after a LF the next line is indent at the
+           * length of the prefix.  Note that we do not yet include
+           * the length of the timestamp and pid in the indent
+           * computation.  */
+          const char *p, *pend;
+
+          for (p = fmt; (pend = strchr (p, '\n')); p = pend+1)
+            es_fprintf_unlocked (logstream, "%*s%.*s",
+                                 (int)((p != fmt
+                                        && (with_prefix || force_prefixes))
+                                       ?strlen (prefix_buffer)+2:0), "",
+                                 (int)(pend - p)+1, p);
+          es_fputs_unlocked (p, logstream);
+        }
       else
         es_vfprintf_unlocked (logstream, fmt, arg_ptr);
       if (*fmt && fmt[strlen(fmt)-1] != '\n')
@@ -769,12 +783,13 @@ do_log_ignore_arg (int level, const char *str, ...)
 }
 
 
+/* Log STRING at LEVEL but indent from the second line on by the
+ * length of the prefix.  */
 void
 log_string (int level, const char *string)
 {
   /* We need a dummy arg_ptr, but there is no portable way to create
-     one.  So we call the do_logv function through a variadic wrapper.
-     MB: Why not just use "%s"?  */
+   * one.  So we call the do_logv function through a variadic wrapper. */
   do_log_ignore_arg (level, string);
 }
 

commit dcad99c98616a6031ddfde313c920339e4012378
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Apr 29 15:41:10 2016 +0200

    gpg: Factor some code code out of tofu.c
    
    * g10/tofu.c (string_to_long): New.
    (string_to_ulong): New.
    (get_single_unsigned_long_cb): Replace strtol/strtoul by new function.
    (get_single_long_cb): Ditto.
    (signature_stats_collect_cb):  Ditto.
    (get_policy): Ditto.
    (show_statistics): Ditto.  Uese es_free instead of free.
    --
    
    There is one minor semantic change: We now accept "nnn.0" always.  The
    old code did not checked for ".0: in show_statistics.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g10/tofu.c b/g10/tofu.c
index a24c52e..e3218b9 100644
--- a/g10/tofu.c
+++ b/g10/tofu.c
@@ -1,5 +1,5 @@
 /* tofu.c - TOFU trust model.
- * Copyright (C) 2015 g10 Code GmbH
+ * Copyright (C) 2015, 2016 g10 Code GmbH
  *
  * This file is part of GnuPG.
  *
@@ -398,7 +398,66 @@ tofu_end_batch_update (void)
         end_transaction (db, 1);
     }
 }
+
+
+
 

+/* Wrapper around strtol which prints a warning in case of a
+ * conversion error.  On success the converted value is stored at
+ * R_VALUE and 0 is returned; on error FALLBACK is stored at R_VALUE
+ * and an error code is returned.  */
+static gpg_error_t
+string_to_long (long *r_value, const char *string, long fallback, int line)
+{
+  gpg_error_t err;
+  char *tail = NULL;
+
+  gpg_err_set_errno (0);
+  *r_value = strtol (string, &tail, 0);
+  if (errno || !(!strcmp (tail, ".0") || !*tail))
+    {
+      err = errno? gpg_error_from_errno (errno) : gpg_error (GPG_ERR_BAD_DATA);
+      log_debug ("%s:%d: "
+                 "strtol failed for DB returned string (tail=%.10s): %s\n",
+                 __FILE__, line, tail, gpg_strerror (err));
+      *r_value = fallback;
+    }
+  else
+    err = 0;
+
+  return err;
+}
+
+
+/* Wrapper around strtoul which prints a warning in case of a
+ * conversion error.  On success the converted value is stored at
+ * R_VALUE and 0 is returned; on error FALLBACK is stored at R_VALUE
+ * and an error code is returned.  */
+static gpg_error_t
+string_to_ulong (unsigned long *r_value, const char *string,
+                 unsigned long fallback, int line)
+{
+  gpg_error_t err;
+  char *tail = NULL;
+
+  gpg_err_set_errno (0);
+  *r_value = strtoul (string, &tail, 0);
+  if (errno || !(!strcmp (tail, ".0") || !*tail))
+    {
+      err = errno? gpg_error_from_errno (errno) : gpg_error (GPG_ERR_BAD_DATA);
+      log_debug ("%s:%d: "
+                 "strtoul failed for DB returned string (tail=%.10s): %s\n",
+                 __FILE__, line, tail, gpg_strerror (err));
+      *r_value = fallback;
+    }
+  else
+    err = 0;
+
+  return err;
+}
+
+
+
 /* Collect results of a select count (*) ...; style query.  Aborts if
    the argument is not a valid integer (or real of the form X.0).  */
 static int
@@ -406,17 +465,13 @@ get_single_unsigned_long_cb (void *cookie, int argc, char **argv,
 			     char **azColName)
 {
   unsigned long int *count = cookie;
-  char *tail = NULL;
 
   (void) azColName;
 
   log_assert (argc == 1);
 
-  errno = 0;
-  *count = strtoul (argv[0], &tail, 0);
-  if (errno || ! (strcmp (tail, ".0") == 0 || *tail == '\0'))
-    /* Abort.  */
-    return 1;
+  if (string_to_ulong (count, argv[0], 0, __LINE__))
+    return 1; /* Abort.  */
   return 0;
 }
 
@@ -1055,17 +1110,14 @@ static int
 get_single_long_cb (void *cookie, int argc, char **argv, char **azColName)
 {
   long *count = cookie;
-  char *tail = NULL;
 
   (void) azColName;
 
   log_assert (argc == 1);
 
-  errno = 0;
-  *count = strtol (argv[0], &tail, 0);
-  if (errno || ! (strcmp (tail, ".0") == 0 || *tail == '\0'))
-    /* Abort.  */
-    return 1;
+  if (string_to_long (count, argv[0], 0, __LINE__))
+    return 1; /* Abort.  */
+
   return 0;
 }
 
@@ -1356,43 +1408,28 @@ signature_stats_collect_cb (void *cookie, int argc, char **argv,
 			    char **azColName, sqlite3_stmt *stmt)
 {
   struct signature_stats **statsp = cookie;
-  char *tail;
   int i = 0;
   enum tofu_policy policy;
   long time_ago;
   unsigned long count;
+  long along;
 
   (void) azColName;
   (void) stmt;
 
   i ++;
 
-  tail = NULL;
-  errno = 0;
-  policy = strtol (argv[i], &tail, 0);
-  if (errno || ! (strcmp (tail, ".0") == 0 || *tail == '\0'))
-    {
-      /* Abort.  */
-      log_error ("%s: Error converting %s to an integer (tail = '%s')\n",
-		 __func__, argv[i], tail);
-      return 1;
-    }
+  if (string_to_long (&along, argv[i], 0, __LINE__))
+    return 1;  /* Abort */
+  policy = along;
   i ++;
 
   if (! argv[i])
     time_ago = 0;
   else
     {
-      tail = NULL;
-      errno = 0;
-      time_ago = strtol (argv[i], &tail, 0);
-      if (errno || ! (strcmp (tail, ".0") == 0 || *tail == '\0'))
-        {
-          /* Abort.  */
-          log_error ("%s: Error converting %s to an integer (tail = '%s')\n",
-                     __func__, argv[i], tail);
-          return 1;
-        }
+      if (string_to_long (&time_ago, argv[i], 0, __LINE__))
+        return 1; /* Abort.  */
     }
   i ++;
 
@@ -1402,16 +1439,8 @@ signature_stats_collect_cb (void *cookie, int argc, char **argv,
     count = 0;
   else
     {
-      tail = NULL;
-      errno = 0;
-      count = strtoul (argv[i], &tail, 0);
-      if (errno || ! (strcmp (tail, ".0") == 0 || *tail == '\0'))
-        {
-          /* Abort.  */
-          log_error ("%s: Error converting %s to an integer (tail = '%s')\n",
-                     __func__, argv[i], tail);
-          return 1;
-        }
+      if (string_to_ulong (&count, argv[i], 0, __LINE__))
+        return 1; /* Abort */
     }
   i ++;
 
@@ -1449,8 +1478,8 @@ get_policy (struct dbs *dbs, const char *fingerprint, const char *email,
   int rc;
   char *err = NULL;
   strlist_t strlist = NULL;
-  char *tail = NULL;
   enum tofu_policy policy = _tofu_GET_POLICY_ERROR;
+  long along;
 
   db = getdb (dbs, email, DB_EMAIL);
   if (! db)
@@ -1494,15 +1523,14 @@ get_policy (struct dbs *dbs, const char *fingerprint, const char *email,
 
   /* The result has the right form.  */
 
-  errno = 0;
-  policy = strtol (strlist->d, &tail, 0);
-  if (errno || *tail != '\0')
+  if (string_to_long (&along, strlist->d, 0, __LINE__))
     {
       log_error (_("error reading TOFU database: %s\n"),
                  gpg_strerror (GPG_ERR_BAD_DATA));
       print_further_info ("bad value for policy: %s", strlist->d);
       goto out;
     }
+  policy = along;
 
   if (! (policy == TOFU_POLICY_AUTO
 	 || policy == TOFU_POLICY_GOOD
@@ -2347,52 +2375,24 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
               fingerprint_pp);
   else
     {
-      char *tail = NULL;
       signed long messages;
       signed long first_seen_ago;
       signed long most_recent_seen_ago;
 
       log_assert (strlist_length (strlist) == 3);
 
-      errno = 0;
-      messages = strtol (strlist->d, &tail, 0);
-      if (errno || *tail != '\0')
-	/* Abort.  */
-	{
-	  log_debug ("%s:%d: Couldn't convert %s (messages) to an int: %s.\n",
-		     __func__, __LINE__, strlist->d, strerror (errno));
-	  messages = -1;
-	}
+      string_to_long (&messages, strlist->d, -1, __LINE__);
 
       if (messages == 0 && *strlist->next->d == '\0')
-	/* min(NULL) => NULL => "".  */
-        {
+        { /* min(NULL) => NULL => "".  */
           first_seen_ago = -1;
           most_recent_seen_ago = -1;
         }
       else
 	{
-	  errno = 0;
-	  first_seen_ago = strtol (strlist->next->d, &tail, 0);
-	  if (errno || *tail != '\0')
-	    /* Abort.  */
-	    {
-	      log_debug ("%s:%d: Couldn't convert %s (first_seen) to an int: %s.\n",
-			 __func__, __LINE__,
-			 strlist->next->d, strerror (errno));
-	      first_seen_ago = 0;
-	    }
-
-	  errno = 0;
-	  most_recent_seen_ago = strtol (strlist->next->next->d, &tail, 0);
-	  if (errno || *tail != '\0')
-	    /* Abort.  */
-	    {
-	      log_debug ("%s:%d: Couldn't convert %s (most_recent_seen) to an int: %s.\n",
-			 __func__, __LINE__,
-			 strlist->next->next->d, strerror (errno));
-	      most_recent_seen_ago = 0;
-	    }
+          string_to_long (&first_seen_ago, strlist->next->d, 0, __LINE__);
+	  string_to_long (&most_recent_seen_ago, strlist->next->next->d, 0,
+                          __LINE__);
 	}
 
       if (messages == -1 || first_seen_ago == 0)
@@ -2493,7 +2493,7 @@ show_statistics (struct dbs *dbs, const char *fingerprint,
               xfree (tmp);
 	      log_info ("%s", text);
               xfree (text);
-	      free (set_policy_command);
+	      es_free (set_policy_command);
 	    }
 	}
     }

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

Summary of changes:
 common/logging.c |  21 ++++++-
 g10/tofu.c       | 164 +++++++++++++++++++++++++++----------------------------
 2 files changed, 100 insertions(+), 85 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list