Skip to content

Commit

Permalink
block: Fix NULL dereference on empty drive error
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
  • Loading branch information
kevmw committed Mar 5, 2018
1 parent 9d9b4b6 commit bfe1a14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions block/block-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions qapi/block-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -3676,7 +3676,8 @@
#
# @node-name: node name. Note that errors may be reported for the root node
# that is directly attached to a guest device rather than for the
# node where the error occurred. (Since: 2.8)
# node where the error occurred. The node name is not present if
# the drive is empty. (Since: 2.8)
#
# @operation: I/O operation
#
Expand Down Expand Up @@ -3707,7 +3708,8 @@
#
##
{ 'event': 'BLOCK_IO_ERROR',
'data': { 'device': 'str', 'node-name': 'str', 'operation': 'IoOperationType',
'data': { 'device': 'str', '*node-name': 'str',
'operation': 'IoOperationType',
'action': 'BlockErrorAction', '*nospace': 'bool',
'reason': 'str' } }

Expand Down

0 comments on commit bfe1a14

Please sign in to comment.