changeset 320:1628615d904e

Replaced snprintf and static buffers with xasprintf.
author Sascha Wilde <wilde@intevation.de>
date Fri, 04 Apr 2014 18:00:40 +0200
parents 4077eff1dd39
children 824ef90a6721
files cinst/mozilla.c
diffstat 1 files changed, 29 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/cinst/mozilla.c	Fri Apr 04 17:58:14 2014 +0200
+++ b/cinst/mozilla.c	Fri Apr 04 18:00:40 2014 +0200
@@ -152,7 +152,7 @@
   char line[LINEBUFLEN];
   char *key;
   char *value;
-  char path[LINEBUFLEN];
+  char *path = NULL;
   char *fqpath;
   bool inprofile = false;
   bool relative_path = false;
@@ -182,9 +182,9 @@
               if (str_equal(key, "Path"))
                 {
                   if (relative_path)
-                    snprintf(path, LINEBUFLEN, "%s/%s", inifile_dirname, value);
+                    xasprintf(&path, "%s/%s", inifile_dirname, value);
                   else
-                    strncpy(path, value, LINEBUFLEN);
+                    xasprintf(&path, "%s", value); /* FIXME: LOOKS STUPID! */
                   if ((fqpath = port_realpath(path)) != NULL)
                     {
                       DEBUGPRINTF("Found profile path: '%s'\n", fqpath);
@@ -196,6 +196,7 @@
                       DEBUGPRINTF("WARN!  Non existent profile path: '%s'\n", path);
                       exit_code |= WARN_MOZ_PROFILE_DOES_NOT_EXIST;
                     }
+                  free(path);
                 }
               else if (str_equal(key, "IsRelative") &&
                        str_starts_with(value, "1"))
@@ -226,8 +227,7 @@
 get_profile_inis ()
 {
   char **inis = NULL;
-  char path[LINEBUFLEN];
-  char *fqpath;
+  char *mozpath, *fqpath, *subpath, *ppath;
   DIR *mozdir;
   struct dirent *mozdirent;
   char *confbase = get_conf_basedir();
@@ -235,33 +235,33 @@
 
   for (int i=0; confdirs[i] != NULL; i++)
     {
-      snprintf(path, LINEBUFLEN, "%s/%s",
-               confbase,
-               confdirs[i]);
-      if ((mozdir = opendir(path)) != NULL)
+      xasprintf(&mozpath,"%s/%s", confbase, confdirs[i]);
+      if ((mozdir = opendir(mozpath)) != NULL)
         {
           while ((mozdirent = readdir(mozdir)) != NULL)
             {
-              snprintf(path, LINEBUFLEN, "%s/%s/%s",
-                       confbase,
-                       confdirs[i],
-                       mozdirent->d_name);
-              if (port_isdir(path)
+              xasprintf(&subpath, "%s/%s/%s",
+                        confbase,
+                        confdirs[i],
+                        mozdirent->d_name);
+              if (port_isdir(subpath)
                   && (strcmp(mozdirent->d_name, "..") != 0))
                 {
-                  snprintf(path, LINEBUFLEN, "%s/%s/%s/%s",
-                           confbase,
-                           confdirs[i],
-                           mozdirent->d_name,
-                           "profiles.ini");
-                  DEBUGPRINTF("checking for %s...\n", path);
-                  if ((fqpath = port_realpath(path)) != NULL)
+                  xasprintf(&ppath, "%s/%s/%s/%s",
+                            confbase,
+                            confdirs[i],
+                            mozdirent->d_name,
+                            "profiles.ini");
+                  DEBUGPRINTF("checking for %s...\n", ppath);
+                  if ((fqpath = port_realpath(ppath)) != NULL)
                     {
                       strv_append(&inis, fqpath, strlen(fqpath));
                       DEBUGPRINTF("Found mozilla ini file: '%s'\n", fqpath);
                       free(fqpath);
                     }
+                  free(ppath);
                 }
+              free(subpath);
             }
           closedir(mozdir);
         }
@@ -269,6 +269,7 @@
         {
           DEBUGPRINTF("Could not open %s/%s\n", confbase, confdirs[i]);
         }
+      free(mozpath);
     }
   if (inis == NULL)
     {
@@ -309,15 +310,16 @@
   /* Search for NSS shared DB (used by Chrome/Chromium on GNU/Linux) */
   if (TARGET_LINUX)
     {
-      char buf[LINEBUFLEN], *fqpath;
-      snprintf(buf, LINEBUFLEN, "%s/%s",
-               get_conf_basedir(), NSSSHARED);
-      if ((fqpath = port_realpath(buf)) != NULL)
+      char *path, *fqpath, *sqlpath;
+      xasprintf(&path, "%s/%s", get_conf_basedir(), NSSSHARED);
+      if ((fqpath = port_realpath(path)) != NULL)
         {
-          snprintf(buf, LINEBUFLEN, "sql:%s", fqpath);
-          strv_append(&alldirs, buf, strlen(buf));
+          xasprintf(&sqlpath, "sql:%s", fqpath);
+          strv_append(&alldirs, sqlpath, strlen(sqlpath));
+          free(sqlpath);
           free(fqpath);
         }
+      free(path);
     }
   return alldirs;
 }

http://wald.intevation.org/projects/trustbridge/