Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
block/export: Fix null pointer dereference in error path
There are some error paths in blk_exp_add() that jump to 'fail:' before
'exp' is even created. So we can't just unconditionally access exp->blk.

Add a NULL check, and switch from exp->blk to blk, which is available
earlier, just to be extra sure that we really cover all cases where
BlockDevOps could have been set for it (in practice, this only happens
in drv->create() today, so this part of the change isn't strictly
necessary).

Fixes: Coverity CID 1509238
Fixes: de79b52
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20230510203601.418015-3-kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Tested-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit a184563)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
Kevin Wolf authored and Michael Tokarev committed May 30, 2023
1 parent e631fdd commit d658499
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions block/export/export.c
Expand Up @@ -192,8 +192,10 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)
return exp;

fail:
blk_set_dev_ops(exp->blk, NULL, NULL);
blk_unref(blk);
if (blk) {
blk_set_dev_ops(blk, NULL, NULL);
blk_unref(blk);
}
aio_context_release(ctx);
if (exp) {
g_free(exp->id);
Expand Down

0 comments on commit d658499

Please sign in to comment.