[git] GnuPG - branch, STABLE-BRANCH-2-2, updated. gnupg-2.2.5-53-g6da7aa1

by Werner Koch cvs at cvs.gnupg.org
Mon Apr 9 14:55:13 CEST 2018


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, STABLE-BRANCH-2-2 has been updated
       via  6da7aa1e7c80d214bd9dccb21744919ae191f2c8 (commit)
      from  519e4560e821e4c41432626b241bca7d37143e01 (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 6da7aa1e7c80d214bd9dccb21744919ae191f2c8
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Apr 9 14:44:21 2018 +0200

    gpg,w32: Fix empty homedir when only a drive letter is used.
    
    * common/homedir.c (copy_dir_with_fixup): New.
    (default_homedir): Use here.
    (gnupg_set_homedir): And here .
    --
    
    This actually fixes a couple of cases for Windows.  Both --home-dir
    and GNUPGHOME.  The interpretation of "c:" -> "c:/" might not be the
    correct one but because we need an absolute dir anyway it is the less
    surprising one.  Note that this does not include a full syntax check
    and fixup and thus it is very well possible that the result is not an
    absolute directory.
    
    GnuPG-bug-id: 3720
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/common/homedir.c b/common/homedir.c
index 65cf50f..e9e75d0 100644
--- a/common/homedir.c
+++ b/common/homedir.c
@@ -171,6 +171,62 @@ is_gnupg_default_homedir (const char *dir)
 }
 
 
+/* Helper to remove trailing slashes from NEWDIR.  Return a new
+ * allocated string if that has been done or NULL if there are no
+ * slashes to remove.  Also inserts a missing slash after a Windows
+ * drive letter.  */
+static char *
+copy_dir_with_fixup (const char *newdir)
+{
+  char *result = NULL;
+  char *p;
+
+  if (!*newdir)
+    return NULL;
+
+#ifdef HAVE_W32_SYSTEM
+  if (newdir[0] && newdir[1] == ':'
+      && !(newdir[2] == '/' || newdir[2] == '\\'))
+    {
+      /* Drive letter with missing leading slash.  */
+      p = result = xmalloc (strlen (newdir) + 1 + 1);
+      *p++ = newdir[0];
+      *p++ = newdir[1];
+      *p++ = '\\';
+      strcpy (p, newdir+2);
+
+      /* Remove trailing slashes.  */
+      p = result + strlen (result) - 1;
+      while (p > result+2 && (*p == '/' || *p == '\\'))
+        *p-- = 0;
+    }
+  else if (newdir[strlen (newdir)-1] == '/'
+           || newdir[strlen (newdir)-1] == '\\' )
+    {
+      result = xstrdup (newdir);
+      p = result + strlen (result) - 1;
+      while (p > result
+             && (*p == '/' || *p == '\\')
+             && (p-1 > result && p[-1] != ':')) /* We keep "c:/". */
+        *p-- = 0;
+    }
+
+#else /*!HAVE_W32_SYSTEM*/
+
+  if (newdir[strlen (newdir)-1] == '/')
+    {
+      result = xstrdup (newdir);
+      p = result + strlen (result) - 1;
+      while (p > result && *p == '/')
+        *p-- = 0;
+    }
+
+#endif /*!HAVE_W32_SYSTEM*/
+
+  return result;
+}
+
+
 /* Get the standard home directory.  In general this function should
    not be used as it does not consider a registry value (under W32) or
    the GNUPGHOME environment variable.  It is better to use
@@ -278,18 +334,11 @@ default_homedir (void)
     dir = GNUPG_DEFAULT_HOMEDIR;
   else
     {
-      /* Strip trailing slashes if any.  */
-      if (dir[strlen (dir)-1] == '/')
-        {
-          char *tmp, *p;
-
-          tmp = xstrdup (dir);
-          p = tmp + strlen (tmp) - 1;
-          while (p > tmp && *p == '/')
-            *p-- = 0;
+      char *p;
 
-          dir = tmp;
-        }
+      p = copy_dir_with_fixup (dir);
+      if (p)
+        dir = p;
 
       if (!is_gnupg_default_homedir (dir))
         non_default_homedir = 1;
@@ -432,28 +481,10 @@ gnupg_set_homedir (const char *newdir)
     newdir = default_homedir ();
   else
     {
-      /* Remove trailing slashes from NEWSDIR.  */
-      if (newdir[strlen (newdir)-1] == '/'
-#ifdef HAVE_W32_SYSTEM
-          || newdir[strlen (newdir)-1] == '\\'
-#endif
-          )
-        {
-          char *p;
+      tmp = copy_dir_with_fixup (newdir);
+      if (tmp)
+        newdir = tmp;
 
-          tmp = xstrdup (newdir);
-          p = tmp + strlen (tmp) - 1;
-          while (p > tmp
-                 && (*p == '/'
-#ifdef HAVE_W32_SYSTEM
-                     || *p == '\\'
-#endif
-                     )
-                 )
-            *p-- = 0;
-
-          newdir = tmp;
-        }
       if (!is_gnupg_default_homedir (newdir))
         non_default_homedir = 1;
     }

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

Summary of changes:
 common/homedir.c | 95 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 63 insertions(+), 32 deletions(-)


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




More information about the Gnupg-commits mailing list