Fix for realloc bug and wrong error logging
authorMikulas Patocka <mpatocka@redhat.com>
Tue, 31 Jan 2012 09:51:50 +0000 (10:51 +0100)
committerJens Axboe <axboe@kernel.dk>
Tue, 31 Jan 2012 09:51:50 +0000 (10:51 +0100)
This patch fixes two bugs in blktrace.

1. realloc is called on a wrong memory address (glibc reports heap
corruption if the user sends the output to a pipe, for example "blktrace
/dev/sdc -o -").

2. errno 0 is actually reported if debugfs is not mounted

Mikulas

Signed-off-by: Jens Axboe <axboe@kernel.dk>
blktrace.c

index 72866e23457ec54899e562b7f985f975fd8cba49..b14daf20c29cf740415ab7ff2d9f36707060a22d 100644 (file)
@@ -1330,7 +1330,7 @@ static struct trace_buf *tb_combine(struct trace_buf *prev,
                 * the whole structures, as the other fields
                 * are "static".
                 */
-               prev = realloc(prev->buf, sizeof(*prev) + tot_len);
+               prev = realloc(prev, sizeof(*prev) + tot_len);
                prev->buf = (void *)(prev + 1);
        }
 
@@ -2155,12 +2155,17 @@ static int handle_args(int argc, char *argv[])
                return 1;
        }
 
-       if (statfs(debugfs_path, &st) < 0 || st.f_type != (long)DEBUGFS_TYPE) {
+       if (statfs(debugfs_path, &st) < 0) {
                fprintf(stderr, "Invalid debug path %s: %d/%s\n",
                        debugfs_path, errno, strerror(errno));
                return 1;
        }
 
+       if (st.f_type != (long)DEBUGFS_TYPE) {
+               fprintf(stderr, "Debugfs is not mounted at %s\n", debugfs_path);
+               return 1;
+       }
+
        if (act_mask_tmp != 0)
                act_mask = act_mask_tmp;