Too small arrays for file names
authorVasily Tarasov <tarasov@vasily.name>
Mon, 27 Feb 2012 07:21:11 +0000 (08:21 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 27 Feb 2012 07:21:11 +0000 (08:21 +0100)
In our experiments blktrace/blkparse file names encode a lot of
infomation about the particular experiment.  We noticed that for long
enough file names blkparse does not work.

The reason is that per_cpu_info->fname[] is of 128 bytes. As a result,
in setup_file() function only part of the file name gets to ->fname[].
Then stat() fails and we exit the function. Notice, that no error is
printed in this case.

In the following patch ->fname[] size is increased to POSIX defined
PATH_MAX.

Signed-off-by: Vasily Tarasov <tarasov@vasily.name
Signed-off-by: Jens Axboe <axboe@kernel.dk>
blkparse.c
blktrace.h

index b0b88c394a7e4687c77cb6693ef385cae1c23790..7be73aa9c96db93d9af8b784eac46a5bf14c1df4 100644 (file)
@@ -2839,7 +2839,7 @@ int main(int argc, char *argv[])
                        ofp = fdopen(STDOUT_FILENO, "w");
                        mode = _IOLBF;
                } else {
-                       char ofname[128];
+                       char ofname[PATH_MAX];
 
                        snprintf(ofname, sizeof(ofname) - 1, "%s", output_name);
                        ofp = fopen(ofname, "w");
index 8b3e031119abb90cee712a87b527a6af2c92eed6..5da6dbc42c83b5e1912bd29bf74d3afc7e47dd7d 100644 (file)
@@ -2,6 +2,7 @@
 #define BLKTRACE_H
 
 #include <stdio.h>
+#include <limits.h>
 #include <byteswap.h>
 #include <endian.h>
 
@@ -44,7 +45,7 @@ struct per_cpu_info {
 
        int fd;
        int fdblock;
-       char fname[128];
+       char fname[PATH_MAX];
 
        struct io_stats io_stats;