bioctl(8) only looks at the first character of the -c option argument
and ignores any trailing characters in the argument. Following the
addition of the RAID1C discipline this behaviour can lead to confusion.

This command with a typo ("C1" vs "1C") attempts to create a CRYPTO volume:

# bioctl -cC1 -l /dev/sd1d,/dev/sd2d softraid0                                  
                                               
bioctl: not exactly one partition

With the patch below, "C1" is instead rejected as an invalid raid level:

# /tmp/bioctl -cC1 -l /dev/sd1d,/dev/sd2d softraid0
bioctl: Invalid RAID level

ok?

diff 5ee6e27345c7d0c6d947bafadc8160eb9da3f73b /usr/src
blob - 24d4042d6d6dd2ee997eac511b0816ad47441d35
file + sbin/bioctl/bioctl.c
--- sbin/bioctl/bioctl.c
+++ sbin/bioctl/bioctl.c
@@ -133,6 +133,8 @@ 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)

Reply via email to