perf tools: Misc small fixes
authorOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Sun, 6 Dec 2009 11:10:49 +0000 (20:10 +0900)
committerIngo Molnar <mingo@elte.hu>
Sun, 6 Dec 2009 17:15:02 +0000 (18:15 +0100)
- util/header.c
"len" is aligned to 64. So, it tries to write the out of
long_name buffer.

So, this use "zero_buf" to write aligned area.

- util/trace-event-read.c
"size" is not including nul byte. So, this allocates it, and set '\0'.

- util/trace-event-parse.c
It needs parens to calc correct size.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <87d42s8iiu.fsf_-_@devron.myhome.or.jp>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
tools/perf/util/header.c
tools/perf/util/trace-event-parse.c
tools/perf/util/trace-event-read.c

index 4805e6dfd23c8a77f2ea7a7bf56bc15c8e5a4544..08b6759287f5e7cb9429a611a880b6fbe2991302 100644 (file)
@@ -187,7 +187,9 @@ static int do_write(int fd, const void *buf, size_t size)
 
 static int __dsos__write_buildid_table(struct list_head *head, int fd)
 {
+#define NAME_ALIGN     64
        struct dso *pos;
+       static const char zero_buf[NAME_ALIGN];
 
        list_for_each_entry(pos, head, node) {
                int err;
@@ -197,14 +199,17 @@ static int __dsos__write_buildid_table(struct list_head *head, int fd)
                if (!pos->has_build_id)
                        continue;
                len = pos->long_name_len + 1;
-               len = ALIGN(len, 64);
+               len = ALIGN(len, NAME_ALIGN);
                memset(&b, 0, sizeof(b));
                memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id));
                b.header.size = sizeof(b) + len;
                err = do_write(fd, &b, sizeof(b));
                if (err < 0)
                        return err;
-               err = do_write(fd, pos->long_name, len);
+               err = do_write(fd, pos->long_name, pos->long_name_len + 1);
+               if (err < 0)
+                       return err;
+               err = do_write(fd, zero_buf, len - pos->long_name_len + 1);
                if (err < 0)
                        return err;
        }
index 0302405aa2ca7b0f6e7b77cde32c4b49462ff8c9..6ffe9d63d85d88a4a7297ac2695b6f66a3d62904 100644 (file)
@@ -177,7 +177,7 @@ void parse_proc_kallsyms(char *file, unsigned int size __unused)
                func_count++;
        }
 
-       func_list = malloc_or_die(sizeof(*func_list) * func_count + 1);
+       func_list = malloc_or_die(sizeof(*func_list) * (func_count + 1));
 
        i = 0;
        while (list) {
index 342dfdd43f875117a0306cb7cd4bb5f7618f82db..1744422cafcb43cf7872b2d7daf67c4409f56e3c 100644 (file)
@@ -145,8 +145,9 @@ static void read_proc_kallsyms(void)
        if (!size)
                return;
 
-       buf = malloc_or_die(size);
+       buf = malloc_or_die(size + 1);
        read_or_die(buf, size);
+       buf[size] = '\0';
 
        parse_proc_kallsyms(buf, size);