From: Jens Axboe Date: Tue, 13 Mar 2007 13:16:08 +0000 (+0100) Subject: Obscure file randommap fix X-Git-Tag: fio-1.14~13 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=5afa0d9b2e14194d34001a24007d96536608e651;ds=sidebyside Obscure file randommap fix 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 --- diff --git a/io_u.c b/io_u.c index 10fa188d..fead400c 100644 --- 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));