do_not_depend_on_MAXPATHLEN
authorDebian QA Group <packages@qa.debian.org>
Thu, 17 Mar 2016 22:00:48 +0000 (22:00 +0000)
committerRaspbian forward porter <root@raspbian.org>
Thu, 17 Mar 2016 22:00:48 +0000 (22:00 +0000)
commit b1e6bf3a94360fffb95da6b0a0bc7051ab243225
Author: Maximiliano Curia <maxy@gnuservers.com.ar>
Date:   Mon Jun 10 15:23:25 2013 +0200

    Do not depend on MAXPATHLEN

Gbp-Pq: Name do_not_depend_on_MAXPATHLEN.patch

binsrc/hosting/fcgi/cgi_fcgi.c
libsrc/util/fnsearch.c
libsrc/util/setext.c

index 069509775de1c20dafb6238fbcd26f6165c2aeb3..ae1daca47a1e54d6d6c93cb15be5420b30e826fe 100644 (file)
@@ -55,7 +55,7 @@ typedef struct vfc_fcgi_srv_s
   dk_mutex_t *mtx;
   caddr_t uri;
   int n_servers;
-  char bind_path [MAXPATHLEN];
+  char *bind_path;
 
   int next_req_id;
   dk_set_t requests;
@@ -111,6 +111,7 @@ vfc_fcgi_server_allocate (const char *base_uri, const char *bind_file, char *err
 {
   vfc_fcgi_srv_t *srv = (vfc_fcgi_srv_t *) dk_alloc (sizeof (vfc_fcgi_srv_t));
   caddr_t md5_val = NULL;
+  char *aux;
 
   vfc_printf (("vfc_fcgi_server_allocate base_uri=[%s] bind_file=[%s]\n",
        base_uri,bind_file));
@@ -122,8 +123,9 @@ vfc_fcgi_server_allocate (const char *base_uri, const char *bind_file, char *err
   if (!bind_file)
     md5_val = md5 (srv->uri);
   vfc_printf (("vfc_fcgi_server_allocate md5_val=[%s] \n", md5_val));
-  snprintf (srv->bind_path, sizeof (srv->bind_path), "%s/%s",
-      fcgi_socket_path, bind_file ? bind_file : md5_val);
+  aux = bind_file ? bind_file : md5_val;
+  srv->bind_path = malloc(strlen(fcgi_socket_path) + strlen(aux) + 2);
+  sprintf (srv->bind_path, "%s/%s", fcgi_socket_path, aux);
   id_hash_set (vfc_server_hash, (caddr_t) &srv->uri, (caddr_t) &srv);
   dk_free_box (md5_val);
   vfc_printf (("vfc_fcgi_server_allocate ret =%p\n",
index 62f566ede70a43c0271010f22dd8a61e5e88c0a3..8725613e4a8f21cdfa91d577c800be8851d4935d 100644 (file)
 char *
 fnsearch (const char *filename, const char *path)
 {
-  static char namebuf[MAXPATHLEN];
+  static char *namebuf = NULL;
+  static size_t namebuf_size = 0;
+  size_t new_size;
   const char *cp;
   char *np;
 
   if (path == NULL)
     return NULL;
-  np = namebuf;
   cp = path;
+
+  /* Avoid a call to realloc, whenever possible */
+  new_size = strlen(path) + strlen(filename) + 2;
+  if (namebuf_size < new_size)
+    {
+      /* Ask more than enough space to store the result */
+      /* (realloc of NULL behaves like malloc) */
+      np = realloc(namebuf, new_size);
+      if (np == NULL)
+        return NULL;
+      namebuf_size = new_size;
+      namebuf = np;
+    }
+  else
+    np = namebuf;
+
   while (1)
     {
       if (*cp == PATHSEP || *cp == '\0')
index d7c029591b796b0c64ddb539bb85e0de59568f3f..62f0faa486c4dd39781e69431cfe0dfe1fd69ea5 100644 (file)
 char *
 setext (const char *path, const char *ext, int mode)
 {
-  static char name[MAXPATHLEN];
+  static char *name = NULL;
+  static size_t name_size = 0;
+  size_t new_size;
   char *slash;
   char *dot;
 
+  /* Avoid a call to realloc, whenever possible */
+  new_size = strlen(path) + strlen(ext) + 2;
+  if (name_size < new_size)
+    {
+      /* Ask more than enough space to store the result */
+      /* (realloc of NULL behaves like malloc) */
+      dot = realloc(name, new_size);
+      if (dot == NULL)
+        return NULL;
+      name_size = new_size;
+      name = dot;
+    }
+
   strcpy (name, path);
 
 #ifdef VMS