aboutsummaryrefslogtreecommitdiff
path: root/sys/geom/label
diff options
context:
space:
mode:
authorJaakko Heinonen <jh@FreeBSD.org>2012-12-22 13:43:12 +0000
committerJaakko Heinonen <jh@FreeBSD.org>2012-12-22 13:43:12 +0000
commitefec959c2c458aae6a58b988017d11575b8c2eee (patch)
tree6a7a69724d6858cac1efd17b9d96eb344ad43c18 /sys/geom/label
parentb1e1f725e7ff23f83fd46692247e7243044071fe (diff)
downloadsrc-efec959c2c458aae6a58b988017d11575b8c2eee.tar.gz
src-efec959c2c458aae6a58b988017d11575b8c2eee.zip
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
Notes
Notes: svn path=/head/; revision=244585
Diffstat (limited to 'sys/geom/label')
-rw-r--r--sys/geom/label/g_label.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/sys/geom/label/g_label.c b/sys/geom/label/g_label.c
index 0ea885064a67..66d228a7bd21 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;