From 3a1ab63eb7f1b83ac799c8e94544ef7a20493eb4 Mon Sep 17 00:00:00 2001 From: Lukas Ertl Date: Wed, 4 Feb 2004 22:29:52 +0000 Subject: [PATCH] When creating raid5 or striped plexes, avoid falling out of bounds when checking the given stripe size. Also move the code a bit around to avoid duplication. Approved by: joerg (mentor) --- sys/dev/vinum/vinumconfig.c | 51 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/sys/dev/vinum/vinumconfig.c b/sys/dev/vinum/vinumconfig.c index 8227485f11a8..f556f77b7dda 100644 --- a/sys/dev/vinum/vinumconfig.c +++ b/sys/dev/vinum/vinumconfig.c @@ -1281,7 +1281,9 @@ config_plex(int update) int namedplexno; enum plexstate state = plex_init; /* state to set at end */ int preferme; /* set if we want to be preferred access */ + int stripesize; + stripesize = 0; current_plex = -1; /* forget the previous plex */ preferme = 0; /* nothing special yet */ plexno = get_empty_plex(); /* allocate a plex */ @@ -1339,52 +1341,53 @@ config_plex(int update) case kw_striped: { - int stripesize = sizespec(token[++parameter]); - plex->organization = plex_striped; - if (stripesize % DEV_BSIZE != 0) /* not a multiple of block size, */ - throw_rude_remark(EINVAL, "plex %s: stripe size %d not a multiple of sector size", - plex->name, - stripesize); + + if (++parameter >= tokens) /* No stripe size specified. */ + stripesize = 0; else - plex->stripesize = stripesize / DEV_BSIZE; + stripesize = sizespec(token[parameter]); + break; } case kw_raid4: { - int stripesize = sizespec(token[++parameter]); - plex->organization = plex_raid4; - if (stripesize % DEV_BSIZE != 0) /* not a multiple of block size, */ - throw_rude_remark(EINVAL, "plex %s: stripe size %d not a multiple of sector size", - plex->name, - stripesize); + + if (++parameter >= tokens) /* No stripe size specified. */ + stripesize = 0; else - plex->stripesize = stripesize / DEV_BSIZE; + stripesize = sizespec(token[parameter]); + break; } case kw_raid5: { - int stripesize = sizespec(token[++parameter]); - plex->organization = plex_raid5; - if (stripesize % DEV_BSIZE != 0) /* not a multiple of block size, */ - throw_rude_remark(EINVAL, "plex %s: stripe size %d not a multiple of sector size", - plex->name, - stripesize); + + if (++parameter >= tokens) /* No stripe size specified. */ + stripesize = 0; else - plex->stripesize = stripesize / DEV_BSIZE; + stripesize = sizespec(token[parameter]); + break; } default: throw_rude_remark(EINVAL, "Invalid plex organization"); } - if (isstriped(plex) - && (plex->stripesize == 0)) /* didn't specify a valid stripe size */ - throw_rude_remark(EINVAL, "Need a stripe size parameter"); + if (isstriped(plex)) { + if (stripesize == 0) /* didn't specify a valid stripe size */ + throw_rude_remark(EINVAL, "Need a stripe size parameter"); + else if (stripesize % DEV_BSIZE != 0) + throw_rude_remark(EINVAL, "plex %s: stripe size %d not a multiple of sector size", + plex->name, + stripesize); + else + plex->stripesize = stripesize / DEV_BSIZE; + } break; /*