]> sjero.net Git - wget/commitdiff
Do not use PATH_MAX.
authorCarlos Martín Nieto <carlos@cmartin.tk>
Tue, 26 Jul 2011 10:49:44 +0000 (12:49 +0200)
committerGiuseppe Scrivano <gscrivano@gnu.org>
Tue, 26 Jul 2011 10:49:44 +0000 (12:49 +0200)
src/ChangeLog
src/init.c

index 0dbabfa2f38d279614d4fe6ed0a4319f57879f15..425802d6071eba9d0fdddd6d426e2434cfc15426 100644 (file)
@@ -1,3 +1,7 @@
+2011-07-26  Carlos Martín Nieto  <carlos@cmartin.tk>  (tiny change)
+
+       * init.c (home_dir): Allocate path buffer dinamically.
+
 2011-07-26  Giuseppe Scrivano  <gscrivano@southpole.se>
 
        * retr.c (retrieve_url): Do not register redirects when in spider mode.
index 277d4a74b5c26c5f95129bd3ed5cd9313edea07f..17f9f9e6d7d38ef965a2e49f0192e94a1223e202 100644 (file)
@@ -366,8 +366,9 @@ defaults (void)
 char *
 home_dir (void)
 {
-  static char buf[PATH_MAX];
-  static char *home;
+  static char *buf = NULL;
+  static char *home, *ret;
+  int len;
 
   if (!home)
     {
@@ -380,12 +381,21 @@ home_dir (void)
           const char *_w32_get_argv0 (void); /* in libwatt.a/pcconfig.c */
           char *p;
 
-          strcpy (buf, _w32_get_argv0 ());
+          buff = _w32_get_argv0 ();
+
           p = strrchr (buf, '/');            /* djgpp */
           if (!p)
             p = strrchr (buf, '\\');          /* others */
           assert (p);
-          *p = '\0';
+
+          len = p - buff + 1;
+          buff = malloc (len + 1);
+          if (buff == NULL)
+            return NULL;
+
+          strncpy (buff, _w32_get_argv0 (), len);
+          buff[len] = '\0';
+
           home = buf;
 #elif !defined(WINDOWS)
           /* If HOME is not defined, try getting it from the password
@@ -393,8 +403,7 @@ home_dir (void)
           struct passwd *pwd = getpwuid (getuid ());
           if (!pwd || !pwd->pw_dir)
             return NULL;
-          strcpy (buf, pwd->pw_dir);
-          home = buf;
+          home = pwd->pw_dir;
 #else  /* !WINDOWS */
           /* Under Windows, if $HOME isn't defined, use the directory where
              `wget.exe' resides.  */
@@ -403,7 +412,11 @@ home_dir (void)
         }
     }
 
-  return home ? xstrdup (home) : NULL;
+  ret = home ? xstrdup (home) : NULL;
+  if (buf)
+    free (buf);
+
+  return ret;
 }
 
 /* Check the 'WGETRC' environment variable and return the file name