Fix for crash with more than ~500 jobs
authorJens Axboe <axboe@kernel.dk>
Wed, 18 Apr 2012 18:39:48 +0000 (20:39 +0200)
committerJens Axboe <axboe@kernel.dk>
Wed, 18 Apr 2012 18:39:48 +0000 (20:39 +0200)
We simply overwrite our status output buffer, not a terribly
good idea.

Reported-by: Roger Sibert <Roger_Sibert@xyratex.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
eta.c

diff --git a/eta.c b/eta.c
index 7e837badc6d1b35368f26f82708aab6fe5e207a5..4679a21a1192b0c36f2df0b5016580537cb1f0b8 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -360,7 +360,7 @@ void display_thread_status(struct jobs_eta *je)
 {
        static int linelen_last;
        static int eta_good;
-       char output[512], *p = output;
+       char output[REAL_MAX_JOBS + 512], *p = output;
        char eta_str[128];
        double perc = 0.0;
        int i2p = 0;
@@ -385,6 +385,7 @@ void display_thread_status(struct jobs_eta *je)
                char perc_str[32];
                char *iops_str[2];
                char *rate_str[2];
+               size_t left;
                int l;
 
                if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
@@ -401,7 +402,9 @@ void display_thread_status(struct jobs_eta *je)
                iops_str[0] = num2str(je->iops[0], 4, 1, 0);
                iops_str[1] = num2str(je->iops[1], 4, 1, 0);
 
-               l = sprintf(p, ": [%s] [%s] [%s/%s /s] [%s/%s iops] [eta %s]",
+               left = sizeof(output) - (p - output) - 1;
+
+               l = snprintf(p, left, ": [%s] [%s] [%s/%s /s] [%s/%s iops] [eta %s]",
                                je->run_str, perc_str, rate_str[0],
                                rate_str[1], iops_str[0], iops_str[1], eta_str);
                p += l;