Skip to content

Commit

Permalink
list_one_dev: do not call ublksrv_json_dump with no buffer
Browse files Browse the repository at this point in the history
Only targets spawned by "ublk add -t ..." will have a pid-file
containing the json buffer for its configuration.
So when creating a different type of target, like ./demo_null,
ublksrv_tgt_store_dev_data() is never invoked and thus the buffer
in list_one_dev is null and we segfault inside ublksrv_json_dump.

For now, only call into ublksrv_json_dump iff -v is used and we
have a flag else fall-back to ublksrv_ctrl_dump which can handle
the json buffer being NULL.

In the future we should move ublksrv_tgt_store_dev_data and
ublksrv_tgt_get_dev_data into the public library so that all
targets can store the json buffer like the built-in ones can.

To reproduce:
Start a demo_null target then run "ublk list -v" and it will crash.

Signed-off-by: root <[email protected]>
  • Loading branch information
root authored and ming1 committed Feb 4, 2025
1 parent 534517b commit 9cab9df
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ublksrv_tgt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ static int list_one_dev(int number, bool log, bool verbose)
} else {
const char *buf = ublksrv_tgt_get_dev_data(dev);

if (verbose)
if (verbose && buf)
ublksrv_json_dump(buf);
else
ublksrv_ctrl_dump(dev, buf);
Expand Down

0 comments on commit 9cab9df

Please sign in to comment.