From b98113ec73748007b944a9b5ea5226d4c6d7224a Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Sat, 31 Oct 2015 19:57:29 +0900 Subject: [PATCH] sys/dev/disk/dm: Fix sanity checks for striped target [2/4] Target specific args for striped is redundant in the sense that it has an arg for # of stripes other than the args for actual stripe devices. These two must meet below. ((argc - 2) / 2) == # of stripe devices. e.g. --table '0 100 stripe1 3 10 /dev/da3 0 /dev/da4 0 /dev/da5 0' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8 target args ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 6 device args ^ # of stripe devices ((8 - 2) / 2) = 6/2 = 3 -> 3 stripe devices (/dev/da[345]) --- sys/dev/disk/dm/targets/striped/dm_target_striped.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sys/dev/disk/dm/targets/striped/dm_target_striped.c b/sys/dev/disk/dm/targets/striped/dm_target_striped.c index 94711a2c2f..eb398dde15 100644 --- a/sys/dev/disk/dm/targets/striped/dm_target_striped.c +++ b/sys/dev/disk/dm/targets/striped/dm_target_striped.c @@ -87,6 +87,12 @@ dm_target_stripe_init(dm_table_entry_t *table_en, int argc, char **argv) return ENOTSUP; } + if (argc != (2 + n * 2)) { + kprintf("dm: Invalid argc %d for %d stripe devices\n", + argc, n); + return EINVAL; + } + chunksize = atoi64(argv[1]); if (chunksize < 1 || chunksize * DEV_BSIZE > MAXPHYS) { kprintf("dm: Error unsupported chunk size %jdKB\n", @@ -111,14 +117,12 @@ dm_target_stripe_init(dm_table_entry_t *table_en, int argc, char **argv) argv += 2; for (n = 0, i = 0; n < tsc->stripe_num; ++n) { arg = argv[i++]; - if (arg == NULL) - break; + KKASSERT(arg); tsc->stripe_devs[n].pdev = dm_pdev_insert(arg); if (tsc->stripe_devs[n].pdev == NULL) break; arg = argv[i++]; - if (arg == NULL) - break; + KKASSERT(arg); tsc->stripe_devs[n].offset = atoi64(arg); dm_table_add_deps(table_en, tsc->stripe_devs[n].pdev); } -- 2.41.0