[seahorse-plugins] Bug 604495 - Don't use fixed MAXPATHLEN size buffers



commit d622b7002ae7bc56725205ba2d004a35217ef951
Author: Emilio Pozuelo Monfort <pochu27 gmail com>
Date:   Mon Dec 14 16:26:58 2009 +0100

    Bug 604495 - Don't use fixed MAXPATHLEN size buffers
    
    Use dynamic allocation instead, since MAXPATHLEN may not be
    defined on some platforms. Fixes the build on GNU/Hurd.

 agent/seahorse-agent-io.c          |   33 ++++++++++++++++++---------------
 libseahorse/seahorse-gpg-options.c |   15 ++++++++-------
 2 files changed, 26 insertions(+), 22 deletions(-)
---
diff --git a/agent/seahorse-agent-io.c b/agent/seahorse-agent-io.c
index ffb9417..6fd4609 100644
--- a/agent/seahorse-agent-io.c
+++ b/agent/seahorse-agent-io.c
@@ -69,7 +69,7 @@ static GList *g_connections = NULL;     /* All open connections */
 static gint g_socket = -1;              /* Socket we're listening on */
 static GIOChannel *g_iochannel = NULL;  /* IO channel for above */
 static gint g_iochannel_tag = 0;        /* Event source tag for above */
-static char g_socket_name[MAXPATHLEN];  /* Name of socket we're listening on */
+static char *g_socket_name;             /* Name of socket we're listening on */
 
 struct _SeahorseAgentConn {
     gint stag;                  /* glib source tag */
@@ -138,9 +138,8 @@ seahorse_agent_io_socket ()
     g_assert (g_socket == -1);
 
     /* We build put the socket in a directory called /tmp/seahorse-XXXXXX */
-    t = g_build_filename (g_get_tmp_dir (), SOCKET_DIR, NULL);
-    strncpy (g_socket_name, t, KL (g_socket_name));
-    g_free (t);
+    g_free (g_socket_name);
+    g_socket_name = g_build_filename (g_get_tmp_dir (), SOCKET_DIR, NULL);
 
     /* Make the appropriate directory */
     if (!mkdtemp (g_socket_name)) {
@@ -154,8 +153,9 @@ seahorse_agent_io_socket ()
         g_warning ("couldn't set permissions on directory: %s", strerror (errno));
 
     /* Build the socket name */
-    strncat (g_socket_name, SOCKET_FILE, KL (g_socket_name));
-    g_socket_name[KL (g_socket_name)] = 0;
+    t = g_socket_name;
+    g_socket_name = g_strdup_printf ("%s%s", g_socket_name, SOCKET_FILE);
+    g_free (t);
 
     memset (&addr, 0, sizeof (addr));
     addr.sun_family = AF_UNIX;
@@ -810,16 +810,19 @@ seahorse_agent_io_uninit ()
 
         g_clear_error (&err);
 
-        /* Remove the socket */
-        unlink (g_socket_name);
+        if (g_socket_name) {
+            /* Remove the socket */
+            unlink (g_socket_name);
 
-        /* Remove the directory */
-        t = strrchr (g_socket_name, '/');
-        if (t != NULL) {
-            *t = 0;
-            rmdir (g_socket_name);
-        }
+            /* Remove the directory */
+            t = strrchr (g_socket_name, '/');
+            if (t != NULL) {
+                *t = 0;
+                rmdir (g_socket_name);
+            }
 
-        g_socket_name[0] = 0;
+            g_free (g_socket_name);
+            g_socket_name = NULL;
+        }
     }    
 }
diff --git a/libseahorse/seahorse-gpg-options.c b/libseahorse/seahorse-gpg-options.c
index 32bcca7..949c026 100644
--- a/libseahorse/seahorse-gpg-options.c
+++ b/libseahorse/seahorse-gpg-options.c
@@ -41,7 +41,7 @@
 #define  GPG_VERSION_PREFIX1   "1."
 #define  GPG_VERSION_PREFIX2   "2."
 
-static gchar gpg_homedir[MAXPATHLEN];
+static gchar *gpg_homedir;
 static gboolean gpg_options_inited = FALSE;
 
 static gboolean
@@ -75,6 +75,9 @@ find_config_file (gboolean read, GError **err)
     g_assert (gpg_options_inited);
     g_assert (!err || !*err);
 
+    if (!gpg_homedir)
+        return NULL;
+
     /* Check for and open ~/.gnupg/gpg.conf */
     conf = g_strconcat (gpg_homedir, "/gpg.conf", NULL);
     if (g_file_test (conf, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_EXISTS)) 
@@ -206,16 +209,14 @@ parse_home_directory (gpgme_engine_info_t engine, GError **err)
                     *x = 0;
                     g_strstrip (t);
 
-                    gpg_homedir[0] = 0;
+                    g_free (gpg_homedir);
 
                     /* If it's not a rooted path then expand */
                     if (t[0] == '~') {
-                        g_strlcpy (gpg_homedir, g_get_home_dir (),
-                                   sizeof (gpg_homedir));
-                        t++;
+                        gpg_homedir = g_strconcat (g_get_home_dir(), ++t);
+                    } else {
+                        gpg_homedir = g_strdup (t);
                     }
-
-                    g_strlcat (gpg_homedir, t, sizeof (gpg_homedir));
                     found = TRUE;
                 }
             }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]