From 9cab9df9a0b2bb56950638570f683e80dd278b87 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 29 Jan 2025 04:17:21 +0000 Subject: [PATCH] list_one_dev: do not call ublksrv_json_dump with no buffer 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 --- ublksrv_tgt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ublksrv_tgt.cpp b/ublksrv_tgt.cpp index 10a5107a..73915aca 100644 --- a/ublksrv_tgt.cpp +++ b/ublksrv_tgt.cpp @@ -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);