Fix: Follow struct dirent allocation guidelines of READDIR(3)
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 14 Jul 2015 15:33:41 +0000 (11:33 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 14 Jul 2015 18:10:46 +0000 (14:10 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/config/config.c

index 9b78e17780698a9b30a8c30043108475e7eec5e5..35d9bb2543284811ced1a899a1a8644ff3fda5ff 100644 (file)
@@ -2458,6 +2458,23 @@ end:
        return ret;
 }
 
+/* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */
+static
+struct dirent *alloc_dirent(const char *path)
+{
+       size_t len;
+       long name_max;
+       struct dirent *entry;
+
+       name_max = pathconf(path, _PC_NAME_MAX);
+       if (name_max == -1) {
+               name_max = PATH_MAX;
+       }
+       len = offsetof(struct dirent, d_name) + name_max + 1;
+       entry = zmalloc(len);
+       return entry;
+}
+
 static
 int load_session_from_path(const char *path, const char *session_name,
        struct session_config_validation_ctx *validation_ctx, int override)
@@ -2493,7 +2510,7 @@ int load_session_from_path(const char *path, const char *session_name,
                        goto end;
                }
 
-               entry = zmalloc(sizeof(*entry));
+               entry = alloc_dirent(path);
                if (!entry) {
                        ret = -LTTNG_ERR_NOMEM;
                        goto end;
This page took 0.033448 seconds and 4 git commands to generate.