hw/ufs: Fix code coverity issues

Fixed four ufs-related coverity issues.

The coverity issues and fixes are as follows

1. CID 1519042: Security issue with the rand() function
Changed to use a fixed value (0xab) instead of rand() as
the value for testing

2. CID 1519043: Dereference after null check
Removed useless (redundant) null checks

3. CID 1519050: Out-of-bounds access issue
Fix to pass an array type variable to find_first_bit and
find_next_bit using DECLARE_BITMAP()

4. CID 1519051: Out-of-bounds read issue
Fix incorrect range check for lun

Fix coverity CID: 1519042 1519043 1519050 1519051

Signed-off-by: Jeuk Kim <jeuk20.kim@samsung.com>
This commit is contained in:
Jeuk Kim 2023-09-18 10:02:36 +09:00
parent 63011373ad
commit 97970dae53
3 changed files with 13 additions and 15 deletions

View file

@ -1345,13 +1345,12 @@ static void ufs_lu_realize(SCSIDevice *dev, Error **errp)
return;
}
if (lu->qdev.conf.blk) {
ctx = blk_get_aio_context(lu->qdev.conf.blk);
aio_context_acquire(ctx);
if (!blkconf_blocksizes(&lu->qdev.conf, errp)) {
goto out;
}
ctx = blk_get_aio_context(lu->qdev.conf.blk);
aio_context_acquire(ctx);
if (!blkconf_blocksizes(&lu->qdev.conf, errp)) {
goto out;
}
lu->qdev.blocksize = UFS_BLOCK_SIZE;
blk_get_geometry(lu->qdev.conf.blk, &nb_sectors);
nb_blocks = nb_sectors / (lu->qdev.blocksize / BDRV_SECTOR_SIZE);
@ -1367,10 +1366,9 @@ static void ufs_lu_realize(SCSIDevice *dev, Error **errp)
}
ufs_lu_brdv_init(lu, errp);
out:
if (ctx) {
aio_context_release(ctx);
}
aio_context_release(ctx);
}
static void ufs_lu_unrealize(SCSIDevice *dev)