summaryrefslogtreecommitdiff
path: root/block/block-backend.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-03-05 15:59:35 +0100
committerKevin Wolf <kwolf@redhat.com>2018-03-05 18:45:32 +0100
commitbfe1a14c180ec44c033be12b9151252ffda69292 (patch)
treec0f703563f7578cdaf949e7d70764946ec9b1c8b /block/block-backend.c
parent9d9b4b640f9e583ff4b24dc762630945f3ccc16d (diff)
downloadqemu-bfe1a14c180ec44c033be12b9151252ffda69292.tar.gz
block: Fix NULL dereference on empty drive error
blk_error_action() sends a BLOCK_IO_ERROR QMP event which includes the node name of its root node. If the BlockBackend represents an empty drive, there is no root node, so we should not try to access its node name. Make the field optional in the event and include it only when the BlockBackend isn't empty. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'block/block-backend.c')
-rw-r--r--block/block-backend.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/block/block-backend.c b/block/block-backend.c
index a775a3dd2f..a4421252f8 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1615,10 +1615,11 @@ static void send_qmp_error_event(BlockBackend *blk,
bool is_read, int error)
{
IoOperationType optype;
+ BlockDriverState *bs = blk_bs(blk);
optype = is_read ? IO_OPERATION_TYPE_READ : IO_OPERATION_TYPE_WRITE;
- qapi_event_send_block_io_error(blk_name(blk),
- bdrv_get_node_name(blk_bs(blk)), optype,
+ qapi_event_send_block_io_error(blk_name(blk), !!bs,
+ bs ? bdrv_get_node_name(bs) : NULL, optype,
action, blk_iostatus_is_enabled(blk),
error == ENOSPC, strerror(error),
&error_abort);