diff options
author | jh <jh@FreeBSD.org> | 2012-12-22 13:43:12 +0000 |
---|---|---|
committer | jh <jh@FreeBSD.org> | 2012-12-22 13:43:12 +0000 |
commit | 93c8ab3bc433d3a5ff6415d019149717a2e1eff7 (patch) | |
tree | 6a7a69724d6858cac1efd17b9d96eb344ad43c18 | |
parent | de8a1071d5920bcdea674f08250851affe15dc4f (diff) | |
download | FreeBSD-src-93c8ab3bc433d3a5ff6415d019149717a2e1eff7.zip FreeBSD-src-93c8ab3bc433d3a5ff6415d019149717a2e1eff7.tar.gz |
Mangle label names containing spaces, non-printable characters '%' or
'"'. Mangling is only done for label names read from file system
metadata. Encoding resembles URL encoding. For example, the space
character becomes %20.
Help by: kib
Discussed with: imp, kib, pjd
-rw-r--r-- | UPDATING | 6 | ||||
-rw-r--r-- | sys/geom/label/g_label.c | 23 |
2 files changed, 29 insertions, 0 deletions
@@ -26,6 +26,12 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 10.x IS SLOW: disable the most expensive debugging functionality run "ln -s 'abort:false,junk:false' /etc/malloc.conf".) +20121222: + GEOM_LABEL now mangles label names read from file system metadata. + Mangling affect labels containing spaces, non-printable characters, + '%' or '"'. Device names in /etc/fstab and other places may need to + be updated. + 20121217: By default, only the 10 most recent kernel dumps will be saved. To restore the previous behaviour (no limit on the number of kernel dumps diff --git a/sys/geom/label/g_label.c b/sys/geom/label/g_label.c index 0ea8850..66d228a 100644 --- a/sys/geom/label/g_label.c +++ b/sys/geom/label/g_label.c @@ -34,8 +34,10 @@ __FBSDID("$FreeBSD$"); #include <sys/lock.h> #include <sys/mutex.h> #include <sys/bio.h> +#include <sys/ctype.h> #include <sys/malloc.h> #include <sys/libkern.h> +#include <sys/sbuf.h> #include <sys/sysctl.h> #include <geom/geom.h> #include <geom/geom_slice.h> @@ -138,6 +140,26 @@ g_label_is_name_ok(const char *label) return (1); } +static void +g_label_mangle_name(char *label, size_t size) +{ + struct sbuf *sb; + const u_char *c; + + sb = sbuf_new(NULL, NULL, size, SBUF_FIXEDLEN); + for (c = label; *c != '\0'; c++) { + if (!isprint(*c) || isspace(*c) || *c =='"' || *c == '%') + sbuf_printf(sb, "%%%02X", *c); + else + sbuf_putc(sb, *c); + } + if (sbuf_finish(sb) != 0) + label[0] = '\0'; + else + strlcpy(label, sbuf_data(sb), size); + sbuf_delete(sb); +} + static struct g_geom * g_label_create(struct gctl_req *req, struct g_class *mp, struct g_provider *pp, const char *label, const char *dir, off_t mediasize) @@ -323,6 +345,7 @@ g_label_taste(struct g_class *mp, struct g_provider *pp, int flags __unused) continue; g_topology_unlock(); g_labels[i]->ld_taste(cp, label, sizeof(label)); + g_label_mangle_name(label, sizeof(label)); g_topology_lock(); if (label[0] == '\0') continue; |