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

rrdtool: FTBFS on hurd-i386



Source: rrdtool
Version: 1.4.3-3.1
Severity: important
Tags: patch
User: debian-hurd@lists.debian.org
Usertags: hurd

Hi,

This patch solves the build problems for GNU/Hurd due to PATH_MAX
issues. The solution is to make dynamic string allocations instead of
using fixed length buffers. The patch involves two files, but is
non-trivial.

FIXME:
Still have to free filename at the correct place. And some issues are
still not completely clear.

TODO:
The whole package will be tested with valgrind on GNU/Linux!

Thanks!

(Not submitted yet, comments are welcome.)

diff -ur rrdtool-1.4.3/src/rrd_client.c rrdtool-1.4.3.modified/src/rrd_client.c
--- rrdtool-1.4.3/src/rrd_client.c	2009-10-27 18:49:29.000000000 +0100
+++ rrdtool-1.4.3.modified/src/rrd_client.c	2012-01-24 18:14:06.000000000 +0100
@@ -86,7 +86,11 @@
   {
     if (is_unix)
     {
+#if _POSIX_C_SOURCE >= 200809L
+      resolved_path = realpath (path, NULL);
+#else
       realpath (path, resolved_path);
+#endif
       ret = resolved_path;
     }
     /* else: nothing to do */
@@ -567,7 +571,11 @@
   rrdc_response_t *res;
   int status;
   int i;
+#if _POSIX_C_SOURCE >= 200809L
+  char *file_path = NULL;
+#else
   char file_path[PATH_MAX];
+#endif
 
   memset (buffer, 0, sizeof (buffer));
   buffer_ptr = &buffer[0];
@@ -628,7 +636,11 @@
   size_t buffer_size;
   rrdc_response_t *res;
   int status;
+#if _POSIX_C_SOURCE >= 200809L
+  char *file_path = NULL;
+#else
   char file_path[PATH_MAX];
+#endif
 
   if (filename == NULL)
     return (-1);
diff -ur rrdtool-1.4.3/src/rrd_daemon.c rrdtool-1.4.3.modified/src/rrd_daemon.c
--- rrdtool-1.4.3/src/rrd_daemon.c	2010-03-22 15:51:06.000000000 +0100
+++ rrdtool-1.4.3.modified/src/rrd_daemon.c	2012-01-24 20:06:18.000000000 +0100
@@ -130,7 +130,7 @@
 struct listen_socket_s
 {
   int fd;
-  char addr[PATH_MAX + 1];
+  char *addr;
   int family;
 
   /* state for BATCH processing */
@@ -1087,14 +1087,18 @@
  */
 static void get_abs_path(char **filename, char *tmp)
 {
+  int len;
   assert(tmp != NULL);
   assert(filename != NULL && *filename != NULL);
 
   if (config_base_dir == NULL || **filename == '/')
     return;
 
-  snprintf(tmp, PATH_MAX, "%s/%s", config_base_dir, *filename);
+  len = strlen(config_base_dir) + 1 + strlen(*filename) + 1;
+  tmp = malloc(len);
+  snprintf(tmp, len, "%s/%s", config_base_dir, *filename);
   *filename = tmp;
+  free(tmp);
 } /* }}} static int get_abs_path */
 
 static int flush_file (const char *filename) /* {{{ */
@@ -1185,7 +1189,7 @@
 
 static int handle_request_flush (HANDLER_PROTO) /* {{{ */
 {
-  char *file, file_tmp[PATH_MAX];
+  char *file, *file_tmp = NULL;
   int status;
 
   status = buffer_get_field (&buffer, &buffer_size, &file);
@@ -1240,7 +1244,7 @@
 static int handle_request_pending(HANDLER_PROTO) /* {{{ */
 {
   int status;
-  char *file, file_tmp[PATH_MAX];
+  char *file, *file_tmp = NULL;
   cache_item_t *ci;
 
   status = buffer_get_field(&buffer, &buffer_size, &file);
@@ -1268,7 +1272,7 @@
 {
   int status;
   gboolean found;
-  char *file, file_tmp[PATH_MAX];
+  char *file, *file_tmp = NULL;
 
   status = buffer_get_field(&buffer, &buffer_size, &file);
   if (status != 0)
@@ -1315,7 +1319,7 @@
 
 static int handle_request_update (HANDLER_PROTO) /* {{{ */
 {
-  char *file, file_tmp[PATH_MAX];
+  char *file, *file_tmp = NULL;
   int values_num = 0;
   int status;
   char orig_buf[CMD_MAX];
@@ -1848,8 +1852,8 @@
 static void journal_new_file(void) /* {{{ */
 {
   struct timeval now;
-  int  new_fd;
-  char new_file[PATH_MAX + 1];
+  int  new_fd, len;
+  char *new_file = NULL;
 
   assert(journal_dir != NULL);
   assert(journal_cur != NULL);
@@ -1858,7 +1862,9 @@
 
   gettimeofday(&now, NULL);
   /* this format assures that the files sort in strcmp() order */
-  snprintf(new_file, PATH_MAX, "%s/%s.%010d.%06d",
+  len = strlen(journal_dir) + 1 + strlen(JOURNAL_BASE) + 2 + 2*3*sizeof(int) + 1;
+  new_file = malloc(len);
+  snprintf(new_file, len, "%s/%s.%010d.%06d",
            journal_dir, JOURNAL_BASE, (int)now.tv_sec, (int)now.tv_usec);
 
   new_fd = open(new_file, O_WRONLY|O_CREAT|O_APPEND,
@@ -2081,10 +2087,10 @@
 
 static void journal_init(void) /* {{{ */
 {
-  int had_journal = 0;
+  int had_journal = 0, len;
   DIR *dir;
   struct dirent *dent;
-  char path[PATH_MAX+1];
+  char *path = NULL;
 
   if (journal_dir == NULL) return;
 
@@ -2103,14 +2109,18 @@
    * correct sort order.  TODO: remove after first release
    */
   {
-    char old_path[PATH_MAX+1];
-    snprintf(old_path, PATH_MAX, "%s/%s", journal_dir, JOURNAL_BASE ".old" );
-    snprintf(path,     PATH_MAX, "%s/%s", journal_dir, JOURNAL_BASE ".0000");
+    char * old_path = NULL;
+    len = strlen(journal_dir) + 1 + strlen(JOURNAL_BASE) + 5 + 1;
+    old_path = malloc (len);
+    path = malloc (len);
+    snprintf(old_path, len, "%s/%s", journal_dir, JOURNAL_BASE ".old" );
+    snprintf(path,     len, "%s/%s", journal_dir, JOURNAL_BASE ".0000");
     rename(old_path, path);
 
-    snprintf(old_path, PATH_MAX, "%s/%s", journal_dir, JOURNAL_BASE        );
-    snprintf(path,     PATH_MAX, "%s/%s", journal_dir, JOURNAL_BASE ".0001");
+    snprintf(old_path, len, "%s/%s", journal_dir, JOURNAL_BASE        );
+    snprintf(path,     len, "%s/%s", journal_dir, JOURNAL_BASE ".0001");
     rename(old_path, path);
+    free(old_path);
   }
 
   dir = opendir(journal_dir);
@@ -2120,7 +2130,11 @@
     if (strncmp(dent->d_name, JOURNAL_BASE, strlen(JOURNAL_BASE)))
       continue;
 
-    snprintf(path, PATH_MAX, "%s/%s", journal_dir, dent->d_name);
+    len = strlen(journal_dir) + 1 + strlen(dent->d_name) + 1;
+    if (path != NULL)
+      free(path);
+    path = malloc(len);
+    snprintf(path, len, "%s/%s", journal_dir, dent->d_name);
 
     if (!rrd_add_strdup(&journal_cur->files, &journal_cur->files_num, path))
     {
@@ -2129,6 +2143,7 @@
       break;
     }
   }
+  free(path);
   closedir(dir);
 
   qsort(journal_cur->files, journal_cur->files_num,
@@ -2272,7 +2287,7 @@
   int fd;
   struct sockaddr_un sa;
   listen_socket_t *temp;
-  int status;
+  int status, len;
   const char *path;
   char *path_copy, *dir;
 
@@ -2365,8 +2380,9 @@
 
   listen_fds[listen_fds_num].fd = fd;
   listen_fds[listen_fds_num].family = PF_UNIX;
-  strncpy(listen_fds[listen_fds_num].addr, path,
-          sizeof (listen_fds[listen_fds_num].addr) - 1);
+  len = strlen (path) + 1;
+  listen_fds[listen_fds_num].addr = malloc(len);
+  strncpy(listen_fds[listen_fds_num].addr, path, len);
   listen_fds_num++;
 
   return (0);
@@ -2516,6 +2532,7 @@
 
     if (listen_fds[i].family == PF_UNIX)
       unlink(listen_fds[i].addr);
+      free(listen_fds[i].addr);
   }
 
   free (listen_fds);
@@ -2640,7 +2657,7 @@
 
 static int daemonize (void) /* {{{ */
 {
-  int pid_fd;
+  int pid_fd, len;
   char *base_dir;
 
   daemon_uid = geteuid();
@@ -2664,7 +2681,9 @@
   {
     listen_socket_t sock;
     memset(&sock, 0, sizeof(sock));
-    strncpy(sock.addr, RRDCACHED_DEFAULT_ADDRESS, sizeof(sock.addr)-1);
+    len = strlen(RRDCACHED_DEFAULT_ADDRESS) + 1;
+    sock.addr = malloc(len);
+    strncpy(sock.addr, RRDCACHED_DEFAULT_ADDRESS, len);
     open_listen_socket (&sock);
   }
 
@@ -2768,6 +2787,7 @@
 static int read_options (int argc, char **argv) /* {{{ */
 {
   int option;
+  size_t len;
   int status = 0;
 
   char **permissions = NULL;
@@ -2796,7 +2816,9 @@
         }
         memset(new, 0, sizeof(listen_socket_t));
 
-        strncpy(new->addr, optarg, sizeof(new->addr)-1);
+	len = strlen(optarg) + 1;
+	new->addr = malloc(len);
+        strncpy(new->addr, optarg, len);
 
         /* Add permissions to the socket {{{ */
         if (permissions_len != 0)
@@ -2839,8 +2861,10 @@
                          &config_listen_address_list_len, new))
         {
           fprintf(stderr, "read_options: rrd_add_ptr failed.\n");
+	  free(new);
           return (2);
         }
+	free(new);
       }
       break;
 
@@ -2980,9 +3004,11 @@
 
       case 'b':
       {
-        size_t len;
+#if _POSIX_C_SOURCE >= 200809L
+        char *base_realpath = NULL;
+#else
         char base_realpath[PATH_MAX];
-
+#endif
         if (config_base_dir != NULL)
           free (config_base_dir);
         config_base_dir = strdup (optarg);
@@ -3004,7 +3030,11 @@
          * assumptions possible (we don't have to resolve paths
          * that start with a "/")
          */
+#if _POSIX_C_SOURCE >= 200809L
+      if ((base_realpath = realpath(config_base_dir, NULL)) == NULL)
+#else
         if (realpath(config_base_dir, base_realpath) == NULL)
+#endif
         {
           fprintf (stderr, "Failed to canonicalize the base directory '%s': "
               "%s\n", config_base_dir, rrd_strerror(errno));
@@ -3021,6 +3051,9 @@
         if (len < 1)
         {
           fprintf (stderr, "Invalid base directory: %s\n", optarg);
+#if _POSIX_C_SOURCE >= 200809L
+	  free(base_realpath);
+#endif
           return (4);
         }
 
@@ -3034,15 +3067,21 @@
         }
 
         if (strncmp(config_base_dir,
-                         base_realpath, sizeof(base_realpath)) != 0)
+                         base_realpath, strlen(base_realpath)) != 0)
         {
           fprintf(stderr,
                   "Base directory (-b) resolved via file system links!\n"
                   "Please consult rrdcached '-b' documentation!\n"
                   "Consider specifying the real directory (%s)\n",
                   base_realpath);
+#if _POSIX_C_SOURCE >= 200809L
+	  free(base_realpath);
+#endif
           return 5;
         }
+#if _POSIX_C_SOURCE >= 200809L
+	free(base_realpath);
+#endif
       }
       break;
 

Reply to: