From: kn Date: Fri, 19 Aug 2022 17:49:10 +0000 (+0000) Subject: Improve RAID level parsing X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=24b6f6bc8d78f8083ddb9225f399e60be66a9d42;p=openbsd Improve RAID level parsing Check for numeric levels before checking for single-character ones ("c" and "C") such that a) invalid synopsis (no "-l") is detected as such # bioctl -c 10 vnd0 softraid0 bioctl: Invalid RAID level # ./obj/bioctl -c 10 vnd0 softraid0 usage: bioctl ... and b) ten is correctly treated as valid but unsupported level: # bioctl -c 10 -l vnd0a softraid0 bioctl: Invalid RAID level # ./obj/bioctl -c 10 -l vnd0a softraid0 bioctl: unsupported RAID level Uppercase the abbreviation while here. Feedback OK tb --- diff --git a/sbin/bioctl/bioctl.c b/sbin/bioctl/bioctl.c index 58561e5f30f..de782c4f293 100644 --- a/sbin/bioctl/bioctl.c +++ b/sbin/bioctl/bioctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bioctl.c,v 1.147 2021/02/08 19:05:05 stsp Exp $ */ +/* $OpenBSD: bioctl.c,v 1.148 2022/08/19 17:49:10 kn Exp $ */ /* * Copyright (c) 2004, 2005 Marco Peereboom @@ -133,14 +133,15 @@ main(int argc, char *argv[]) func |= BIOC_CREATERAID; if (strcmp(optarg, "1C") == 0) { cr_level = 0x1C; - } else if (strlen(optarg) != 1) { - errx(1, "Invalid RAID level"); } else if (isdigit((unsigned char)*optarg)) { cr_level = strtonum(optarg, 0, 10, &errstr); if (errstr != NULL) errx(1, "Invalid RAID level"); - } else + } else if (strlen(optarg) == 1) { cr_level = *optarg; + } else { + errx(1, "Invalid RAID level"); + } break; case 'd': /* delete volume */ @@ -863,7 +864,7 @@ bio_createraid(u_int16_t level, char *dev_list, char *key_disk) min_disks = 1; break; default: - errx(1, "unsupported raid level"); + errx(1, "unsupported RAID level"); } if (no_dev < min_disks)