Too small arrays for file names
[blktrace.git] / blkparse.c
index 767b7cdfe8639d592ba911a2a24a25ab32f90b40..7be73aa9c96db93d9af8b784eac46a5bf14c1df4 100644 (file)
@@ -36,7 +36,7 @@
 #include "rbtree.h"
 #include "jhash.h"
 
-static char blkparse_version[] = "1.0.1";
+static char blkparse_version[] = "1.0.4";
 
 struct skip_info {
        unsigned long start, end;
@@ -562,7 +562,9 @@ static struct process_pid_map *add_ppm_hash(pid_t pid, const char *name)
                ppm = malloc(sizeof(*ppm));
                memset(ppm, 0, sizeof(*ppm));
                ppm->pid = pid;
-               strcpy(ppm->comm, name);
+               memset(ppm->comm, 0, sizeof(ppm->comm));
+               strncpy(ppm->comm, name, sizeof(ppm->comm));
+               ppm->comm[sizeof(ppm->comm) - 1] = '\0';
                ppm->hash_next = ppm_hash_table[hash_idx];
                ppm_hash_table[hash_idx] = ppm;
        }
@@ -1675,7 +1677,7 @@ static void dump_io_stats(struct per_dev_info *pdi, struct io_stats *ios,
                fprintf(ofp, " PC Reads Req.:   %s\t\t", size_cnv(x, ios->rrqueue_pc, 0));
                fprintf(ofp, " PC Writes Req.:   %s\n", size_cnv(x, ios->wrqueue_pc, 0));
                fprintf(ofp, " PC Reads Compl.: %s\t\t", size_cnv(x, ios->creads_pc, 0));
-               fprintf(ofp, " PC Writes Compl.: %s\n", size_cnv(x, ios->cwrites, 0));
+               fprintf(ofp, " PC Writes Compl.: %s\n", size_cnv(x, ios->cwrites_pc, 0));
        }
        fprintf(ofp, " IO unplugs:      %'8lu%8c\t", ios->io_unplugs, ' ');
        fprintf(ofp, " Timer unplugs:    %'8lu\n", ios->timer_unplugs);
@@ -1962,6 +1964,7 @@ static int check_cpu_map(struct per_dev_info *pdi)
         * create a map of the cpus we have traces for
         */
        cpu_map = malloc(pdi->cpu_map_max / sizeof(long));
+       memset(cpu_map, 0, sizeof(*cpu_map));
        n = rb_first(&rb_sort_root);
        while (n) {
                __t = rb_entry(n, struct trace, rb_node);
@@ -2354,6 +2357,12 @@ static int ms_prime(struct ms_stream *msp)
                if (verify_trace(bit))
                        goto err;
 
+               if (bit->cpu != pci->cpu) {
+                       fprintf(stderr, "cpu %d trace info has error cpu %d\n",
+                               pci->cpu, bit->cpu);
+                       continue;
+               }
+
                if (bit->action & BLK_TC_ACT(BLK_TC_NOTIFY) && bit->action != BLK_TN_MESSAGE) {
                        handle_notify(bit);
                        output_binary(bit, sizeof(*bit) + bit->pdu_len);
@@ -2682,6 +2691,8 @@ static char usage_str[] =    "\n\n" \
        "[ -M                | --no-msgs\n" \
        "[ -v                | --verbose ]\n" \
        "[ -V                | --version ]\n\n" \
+       "\t-a Only trace specified actions. See documentation\n" \
+       "\t-A Give trace mask as a single value. See documentation\n" \
        "\t-b stdin read batching\n" \
        "\t-d Output file. If specified, binary data is written to file\n" \
        "\t-D Directory to prepend to input file names\n" \
@@ -2828,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");