Re: UFS label limitations

From: Rick C. Petty <rick-freebsd2008_at_kiwi-computer.com>
Date: Thu, 23 Jul 2009 18:27:30 -0500
I posted this patch to freebsd-fs back in December, which allows some
separator characters to be used in UFS labels.  I've attached the patch
below.  des_at_ suggested using strspn(3) instead, so I've attached that
version also.  Is someone willing to commit this into 8.0?  It's rather
innocuous.

-- Rick C. Petty


~~~
~~~  original patch
~~~

--- src/sbin/newfs/newfs.c.orig	2007-03-02 14:07:59.000000000 -0600
+++ src/sbin/newfs/newfs.c	2008-12-15 17:29:26.000000000 -0600
_at__at_ -168,11 +168,15 _at__at_
 		case 'L':
 			volumelabel = optarg;
 			i = -1;
-			while (isalnum(volumelabel[++i]));
-			if (volumelabel[i] != '\0') {
-				errx(1, "bad volume label. Valid characters are alphanumerics.");
-			}
-			if (strlen(volumelabel) >= MAXVOLLEN) {
+			while ((ch = volumelabel[++i]) != '\0')
+				if (ch != '-' && ch != '.' && ch != '_' &&
+				    (ch < '0' || ch > '9') &&
+				    (ch < 'A' || ch > 'Z') &&
+				    (ch < 'a' || ch > 'z'))
+					errx(1,
+					"bad volume label. Valid characters are "
+					"[0-9A-Za-z._-].");
+			if (i >= MAXVOLLEN) {
 				errx(1, "bad volume label. Length is longer than %d.",
 				    MAXVOLLEN);
 			}
--- src/sbin/tunefs/tunefs.c.orig	2008-02-26 14:25:35.000000000 -0600
+++ src/sbin/tunefs/tunefs.c	2008-12-15 17:27:58.000000000 -0600
_at__at_ -153,13 +153,16 _at__at_
 			name = "volume label";
 			Lvalue = optarg;
 			i = -1;
-			while (isalnum(Lvalue[++i]));
-			if (Lvalue[i] != '\0') {
+			while ((ch = Lvalue[++i]) != '\0')
+				if (ch != '-' && ch != '.' && ch != '_' &&
+				    (ch < '0' || ch > '9') &&
+				    (ch < 'A' || ch > 'Z') &&
+				    (ch < 'a' || ch > 'z'))
 				errx(10,
-				"bad %s. Valid characters are alphanumerics.",
+					"bad %s. Valid characters are "
+					"[0-9A-Za-z._-].",
 				    name);
-			}
-			if (strlen(Lvalue) >= MAXVOLLEN) {
+			if (i >= MAXVOLLEN) {
 				errx(10, "bad %s. Length is longer than %d.",
 				    name, MAXVOLLEN - 1);
 			}


~~~
~~~  using strspn instead
~~~

--- src/sbin/newfs/newfs.c.orig	2008-05-03 23:51:38.000000000 -0500
+++ src/sbin/newfs/newfs.c	2009-07-22 16:58:48.000000000 -0500
_at__at_ -167,10 +167,10 _at__at_
 			break;
 		case 'L':
 			volumelabel = optarg;
-			i = -1;
-			while (isalnum(volumelabel[++i]));
+			i = strspn(volumelabel,
+			    "-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz");
 			if (volumelabel[i] != '\0') {
-				errx(1, "bad volume label. Valid characters are alphanumerics.");
+				errx(1, "bad volume label. Valid characters are [0-9A-Za-z._-].");
 			}
 			if (strlen(volumelabel) >= MAXVOLLEN) {
 				errx(1, "bad volume label. Length is longer than %d.",
--- src/sbin/tunefs/tunefs.c.orig	2008-05-03 23:51:52.000000000 -0500
+++ src/sbin/tunefs/tunefs.c	2009-07-22 17:01:23.000000000 -0500
_at__at_ -152,11 +152,11 _at__at_
 			found_arg = 1;
 			name = "volume label";
 			Lvalue = optarg;
-			i = -1;
-			while (isalnum(Lvalue[++i]));
+			i = strspn(Lvalue,
+			    "-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz");
 			if (Lvalue[i] != '\0') {
 				errx(10,
-				"bad %s. Valid characters are alphanumerics.",
+				"bad %s. Valid characters are [0-9A-Za-z._-].",
 				    name);
 			}
 			if (strlen(Lvalue) >= MAXVOLLEN) {
Received on Thu Jul 23 2009 - 21:54:11 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:52 UTC