From d8365957edd930f13628ff473fd52501bd9c5dae Mon Sep 17 00:00:00 2001 From: Mikulas Patocka Date: Tue, 31 Jan 2012 10:51:50 +0100 Subject: [PATCH] Fix for realloc bug and wrong error logging 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 --- blktrace.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/blktrace.c b/blktrace.c index 72866e2..b14daf2 100644 --- a/blktrace.c +++ b/blktrace.c @@ -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; -- 2.25.1