Fix: Check return value of fpathconf
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 4 Dec 2015 22:03:12 +0000 (17:03 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 10 Feb 2016 15:54:28 +0000 (10:54 -0500)
Current glibc has a bug in fpathconf(fd, _PC_NAME_MAX) where it will
fail with a 32bit userland on a 64bit kernel and where the filesystem
has a large block count, see glibc bug #18675.

In any case, we should check this return value because on a failure we
we don't allocate enough memory for dirent and then overflow on the
readdir_r call.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ctf.c

index a617497e05b719d544e5d662137632d4cb3d3718..e626c6cf872c2fb094dbfaebf4a46197a8356372 100644 (file)
@@ -2113,6 +2113,7 @@ int ctf_open_trace_read(struct ctf_trace *td,
        struct dirent *dirent;
        struct dirent *diriter;
        size_t dirent_len;
+       int pc_name_max;
        char *ext;
 
        td->flags = flags;
@@ -2162,8 +2163,15 @@ int ctf_open_trace_read(struct ctf_trace *td,
         * the stream array.
         */
 
-       dirent_len = offsetof(struct dirent, d_name) +
-                       fpathconf(td->dirfd, _PC_NAME_MAX) + 1;
+       pc_name_max = fpathconf(td->dirfd, _PC_NAME_MAX);
+       if (pc_name_max < 0) {
+               perror("Error on fpathconf");
+               fprintf(stderr, "[error] Failed to get _PC_NAME_MAX for path \"%s\".\n", path);
+               ret = -1;
+               goto error_metadata;
+       }
+
+       dirent_len = offsetof(struct dirent, d_name) + pc_name_max + 1;
 
        dirent = malloc(dirent_len);
 
This page took 0.026508 seconds and 4 git commands to generate.