Skip to content

Commit e9d0212

Browse files
committed
drbdadm: fix segfault if we don't know about peer devices
Trying to do below "exploded" for me: ``` drbdsetup show > tmp drbdadm -c tmp -d up all ``` With an incomplete config file (like the one obtained from "drbdsetup show"), we may not know about peer volumes. Avoid to dereference NULL volumes.
1 parent abd47fb commit e9d0212

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

user/v9/drbdadm_main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,12 @@ int adm_peer_device(const struct cfg_ctx *ctx)
20272027
const char *argv[MAX_ARGS];
20282028
int argc = 0;
20292029

2030+
if (!vol) {
2031+
log_err("No volume?!\n");
2032+
if (dry_run)
2033+
return 0;
2034+
exit(E_THINKO);
2035+
}
20302036
peer_device = find_peer_device(conn, vol->vnr);
20312037
if (!peer_device) {
20322038
log_err("Could not find peer_device object!\n");
@@ -2371,7 +2377,9 @@ static int adm_up(const struct cfg_ctx *ctx)
23712377

23722378
tmp2_ctx = tmp_ctx;
23732379
tmp2_ctx.vol = volume_by_vnr(&conn->peer->volumes, peer_device->vnr);
2374-
schedule_deferred_cmd(&peer_device_options_cmd, &tmp2_ctx, dcmd, 0);
2380+
if (tmp2_ctx.vol)
2381+
schedule_deferred_cmd(&peer_device_options_cmd, &tmp2_ctx, dcmd, 0);
2382+
/* else: oops? incomplete config file? */
23752383
}
23762384
}
23772385

user/v9/drbdadm_postparse.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ bool peer_diskless(struct peer_device *peer_device)
482482
struct d_volume *vol;
483483

484484
vol = volume_by_vnr(&peer_device->connection->peer->volumes, peer_device->vnr);
485-
return vol->disk == NULL;
485+
/* Do we even know? Maybe we have an incomplete config file. */
486+
return vol ? vol->disk == NULL : false;
486487
}
487488

488489

0 commit comments

Comments
 (0)