io_u_qiter: Fix buffer overrun
authorSitsofe Wheeler <sitsofe@yahoo.com>
Thu, 13 Feb 2014 07:06:40 +0000 (07:06 +0000)
committerJens Axboe <axboe@fb.com>
Thu, 13 Feb 2014 16:18:29 +0000 (09:18 -0700)
commit6a7a92156a09ff66fd3e0ea062f2cdb339ca73c5
tree46957dd9000b8818842ab70df24690e49dd4a2c6
parent2d60ad8ee888dcb0cabc8c561b996db79dca4b00
io_u_qiter: Fix buffer overrun

In io_u_queue.h the io_u_qiter macro is loops around io_u_queue
structures. The problem comes with the end of loop initialisation:
i++, io_u = (q)->io_us[i]
For example, if io_us consists of one element and i is 0 then after the
first iteration is completed i++, io_u = (q)->io_us[i] will access
beyond the end of io_us.

Fix this by moving io_u initialisation to the expression part of the for
loop (yuck).

Found by Dr Memory.

Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
io_u_queue.h