Obscure file randommap fix
authorJens Axboe <jens.axboe@oracle.com>
Tue, 13 Mar 2007 13:16:08 +0000 (14:16 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Tue, 13 Mar 2007 13:16:08 +0000 (14:16 +0100)
If file size < block and no size is given, we could be generating
a random offset within -1 and deref ->file_map[] beyond its size.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
io_u.c

diff --git a/io_u.c b/io_u.c
index 10fa188..fead400 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -109,6 +109,9 @@ static int get_next_offset(struct thread_data *td, struct io_u *io_u)
                unsigned long long max_blocks = f->file_size / td->min_bs[ddir];
                int loops = 5;
 
+               if (!max_blocks)
+                       return 1;
+
                do {
                        r = os_random_long(&td->random_state);
                        b = ((max_blocks - 1) * r / (unsigned long long) (RAND_MAX+1.0));