sandbox: check lseek return value in handle_ufi_command

Invoking lseek() may result in an error. Handle it.

Addresses-Coverity-ID: 376212 ("Error handling issues  (CHECKED_RETURN)")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:
Heinrich Schuchardt 2022-11-10 08:40:30 +01:00 committed by Simon Glass
parent 8dd0059f77
commit b3a680a47a

View File

@ -188,15 +188,19 @@ static int handle_ufi_command(struct sandbox_flash_priv *priv, const void *buff,
struct scsi_emul_info *info = &priv->eminfo; struct scsi_emul_info *info = &priv->eminfo;
const struct scsi_cmd *req = buff; const struct scsi_cmd *req = buff;
int ret; int ret;
off_t offset;
ret = sb_scsi_emul_command(info, req, len); ret = sb_scsi_emul_command(info, req, len);
if (!ret) { if (!ret) {
setup_response(priv); setup_response(priv);
} else if ((ret == SCSI_EMUL_DO_READ || ret == SCSI_EMUL_DO_WRITE) && } else if ((ret == SCSI_EMUL_DO_READ || ret == SCSI_EMUL_DO_WRITE) &&
priv->fd != -1) { priv->fd != -1) {
os_lseek(priv->fd, info->seek_block * info->block_size, offset = os_lseek(priv->fd, info->seek_block * info->block_size,
OS_SEEK_SET); OS_SEEK_SET);
setup_response(priv); if (offset == (off_t)-1)
setup_fail_response(priv);
else
setup_response(priv);
} else { } else {
setup_fail_response(priv); setup_fail_response(priv);
} }