Author: jh
Date: Sat Dec 22 13:43:12 2012
New Revision: 244585
URL: http://svnweb.freebsd.org/changeset/base/244585

Log:
  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

Modified:
  head/UPDATING
  head/sys/geom/label/g_label.c

Modified: head/UPDATING
==============================================================================
--- head/UPDATING       Sat Dec 22 13:33:28 2012        (r244584)
+++ head/UPDATING       Sat Dec 22 13:43:12 2012        (r244585)
@@ -26,6 +26,12 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 10
        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

Modified: head/sys/geom/label/g_label.c
==============================================================================
--- head/sys/geom/label/g_label.c       Sat Dec 22 13:33:28 2012        
(r244584)
+++ head/sys/geom/label/g_label.c       Sat Dec 22 13:43:12 2012        
(r244585)
@@ -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
                        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;
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to