• Daniel Scheller's avatar
    media: ddbridge/mci: protect against out-of-bounds array access in stop() · 525cac75
    Daniel Scheller authored
    In stop(), an (unlikely) out-of-bounds write error can occur when setting
    the demod_in_use element indexed by state->demod to zero, as state->demod
    isn't checked for being in the range of the array size of demod_in_use, and
    state->demod maybe carrying the magic 0xff (demod unused) value. Prevent
    this by checking state->demod not exceeding the array size before setting
    the element value. To make the code a bit easier to read, replace the magic
    value and the number of array elements with defines, and use them at a few
    more places.
    
    Detected by CoverityScan, CID#1468550 ("Out-of-bounds write")
    
    Thanks to Colin for reporting the problem and providing an initial patch.
    
    Fixes: daeeb131 ("media: ddbridge: initial support for MCI-based MaxSX8 cards")
    Reported-by: default avatarColin Ian King <colin.king@canonical.com>
    Cc: Ralph Metzler <rjkm@metzlerbros.de>
    Signed-off-by: default avatarDaniel Scheller <d.scheller@gmx.net>
    Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
    525cac75
ddbridge-mci.c 13.2 KB