aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2023-05-10 22:35:55 +0200
committerKevin Wolf <kwolf@redhat.com>2023-05-19 19:12:12 +0200
commita184563778f2b8970eb93291f08108e66432a575 (patch)
treef48f0961131195b8729cbaf001753c57a3645ab0 /block
parent4db7ba3b87447fd06cd7e23dab69fdae6011496d (diff)
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: de79b52604e43fdeba6cee4f5af600b62169f2d2 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>
Diffstat (limited to 'block')
-rw-r--r--block/export/export.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/block/export/export.c b/block/export/export.c
index 62c7c22d45..a5c8f42f53 100644
--- a/block/export/export.c
+++ b/block/export/export.c
@@ -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);