kern/149762: volume labels with rogue characters

Walter C. Pelissero walter at pelissero.de
Wed Aug 18 11:02:32 UTC 2010


The patch submitted just before contained a bug.  Please disregard and
consider the following instead:

*** g_label.c	22 Jun 2010 08:17:20 -0000	1.24.2.4
--- g_label.c	18 Aug 2010 10:56:09 -0000
***************
*** 136,141 ****
--- 136,161 ----
  	return (1);
  }
  
+ static int sanitation_level = 1;
+ SYSCTL_INT(_kern_geom_label, OID_AUTO, sanitation, CTLFLAG_RW,
+ 	   &sanitation_level, 0,
+ 	   "Correction applied to labels: 0 = replace '/'s only, 1 = '/' + whitespace and ctrls, 2 = '/' + anything but ASCII printables");
+ 
+ static void
+ sanitise_name (char *name)
+ {
+ 	char *p;
+ 
+ 	for (p = name; *p; ++p) {
+ 		if (*p == '/')
+ 			*p = '#';
+ 		else if (sanitation_level > 0 && *p <= ' ')
+ 			*p = '_';
+ 		else if (sanitation_level > 1 && *p > '~')
+ 			*p = '#';
+ 	}
+ }
+ 
  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)
***************
*** 156,161 ****
--- 176,182 ----
  	gp = NULL;
  	cp = NULL;
  	snprintf(name, sizeof(name), "%s/%s", dir, label);
+ 	sanitise_name(name + strlen(dir) + 1);
  	LIST_FOREACH(gp, &mp->geom, geom) {
  		pp2 = LIST_FIRST(&gp->provider);
  		if (pp2 == NULL)


-- 
walter pelissero
http://www.pelissero.de


More information about the freebsd-bugs mailing list