diff options
author | pjd <pjd@FreeBSD.org> | 2009-09-04 09:39:06 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2009-09-04 09:39:06 +0000 |
commit | 39353b796aec156aa63e57bcfb1b08a43b5f0837 (patch) | |
tree | 335bb4597a0b85c1beaac2aad8e8c3c042c7855b /sys/geom | |
parent | e49c4b7112deed7be5f8aaf7357f7730384ec9b3 (diff) | |
download | FreeBSD-src-39353b796aec156aa63e57bcfb1b08a43b5f0837.zip FreeBSD-src-39353b796aec156aa63e57bcfb1b08a43b5f0837.tar.gz |
Simplify g_disk_ident_adjust() function and allow any printable character
in serial number.
Discussed with: trasz
Obtained from: Wheel Sp. z o.o. (http://www.wheel.pl)
Diffstat (limited to 'sys/geom')
-rw-r--r-- | sys/geom/geom_disk.c | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/sys/geom/geom_disk.c b/sys/geom/geom_disk.c index 20998bd..4cf3196 100644 --- a/sys/geom/geom_disk.c +++ b/sys/geom/geom_disk.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include <sys/sysctl.h> #include <sys/bio.h> #include <sys/conf.h> +#include <sys/ctype.h> #include <sys/fcntl.h> #include <sys/malloc.h> #include <sys/sysctl.h> @@ -400,39 +401,25 @@ g_disk_destroy(void *ptr, int flag) } /* - * We only allow [a-zA-Z0-9-_@#%.:] characters, the rest is converted to 'x<HH>'. + * We only allow printable characters in disk ident, + * the rest is converted to 'x<HH>'. */ static void g_disk_ident_adjust(char *ident, size_t size) { - char newid[DISK_IDENT_SIZE], tmp[4]; - size_t len; - char *p; - - bzero(newid, sizeof(newid)); - len = 0; - for (p = ident; *p != '\0' && len < sizeof(newid) - 1; p++) { - switch (*p) { - default: - if ((*p < 'a' || *p > 'z') && - (*p < 'A' || *p > 'Z') && - (*p < '0' || *p > '9')) { - snprintf(tmp, sizeof(tmp), "x%02hhx", *p); - strlcat(newid, tmp, sizeof(newid)); - len += 3; - break; - } - /* FALLTHROUGH */ - case '-': - case '_': - case '@': - case '#': - case '%': - case '.': - case ':': - newid[len++] = *p; - break; + char *p, tmp[4], newid[DISK_IDENT_SIZE]; + + newid[0] = '\0'; + for (p = ident; *p != '\0'; p++) { + if (isprint(*p)) { + tmp[0] = *p; + tmp[1] = '\0'; + } else { + snprintf(tmp, sizeof(tmp), "x%02hhx", + *(unsigned char *)p); } + if (strlcat(newid, tmp, sizeof(newid)) >= sizeof(newid)) + break; } bzero(ident, size); strlcpy(ident, newid, size); |