Skip to content

Commit 069504c

Browse files
committed
nvme/{tree,fabrics}: do not crash when accessing disconnected controllers
When a controller is disconnected it will just clear the volatile attributes, but remain part of the tree structure. So when traversing the tree one could access a disconnected controller, but then c->name is NULL. So fixup all places calling nvme_ctrl_get_name() to ensure that they don't crash on an empty name. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent d806d2e commit 069504c

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/nvme/fabrics.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,13 @@ static struct nvmf_discovery_log *nvme_discovery_log(
11491149
.uuidx = NVME_UUID_NONE,
11501150
};
11511151

1152+
if (!name) {
1153+
nvme_msg(r, LOG_ERR,
1154+
"controller not connected\n");
1155+
errno = ENOTCONN;
1156+
return NULL;
1157+
}
1158+
11521159
log = __nvme_alloc(sizeof(*log));
11531160
if (!log) {
11541161
nvme_msg(r, LOG_ERR,

src/nvme/tree.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ static void nvme_filter_ctrl(nvme_root_t r, nvme_ctrl_t c,
245245
if (f(NULL, c, NULL, f_args))
246246
return;
247247

248+
if (!nvme_ctrl_get_name(c))
249+
return;
250+
248251
nvme_msg(r, LOG_DEBUG, "filter out controller %s\n",
249252
nvme_ctrl_get_name(c));
250253
nvme_free_ctrl(c);
@@ -1815,6 +1818,8 @@ nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
18151818

18161819
c = p ? nvme_subsystem_next_ctrl(s, p) : nvme_subsystem_first_ctrl(s);
18171820
for (; c != NULL; c = nvme_subsystem_next_ctrl(s, c)) {
1821+
if (!nvme_ctrl_get_name(c))
1822+
continue;
18181823
if (ctrl_match(c, &candidate)) {
18191824
matching_c = c;
18201825
break;

0 commit comments

Comments
 (0)