BUG: 'glabel label' name's lenght, is truncated without err/warn

Lucas Holt luke at foolishgames.com
Sat Nov 5 14:24:07 UTC 2011


On Nov 5, 2011, at 7:02 AM, rank1seeker at gmail.com wrote:

> 8.2R p4 both i386/amd64
> 
> 
> Supplied name of 16 chars
> --
> # glabel label -v swap_679592d048a ada0s3b
> Metadata value stored on ada0s3b.
> Done.
> --
> 
> Truncated to 15 chars
> --
> # ll /dev/label
> total 0
> crw-r-----  1 root  operator  -   0, 133 Nov  5 11:41:54 2011 swap_679592d048
> --
> 


The maximum size for the field is 16 so that explains the behavior you're seeing.  It's strlcpy'd in.  Something like the following patch would work:

--- src/sbin/geom/class/label/geom_label.c	2008/11/21 21:05:31	1.3
+++ src/sbin/geom/class/label/geom_label.c	2011/11/05 14:15:23	1.4
@@ -118,6 +118,12 @@ label_label(struct gctl_req *req)
 		return;
 	}
 
+	label = gctl_get_ascii(req, "arg0");
+	if (strlen(label) > 15) {
+		gctl_error(req, "Label cannot exceed 15 characters");
+		return;
+	}
+
 	/*
 	 * Clear last sector first to spoil all components if device exists.
 	 */
@@ -131,7 +137,6 @@ label_label(struct gctl_req *req)
 
 	strlcpy(md.md_magic, G_LABEL_MAGIC, sizeof(md.md_magic));
 	md.md_version = G_LABEL_VERSION;
-	label = gctl_get_ascii(req, "arg0");
 	strlcpy(md.md_label, label, sizeof(md.md_label));
 	md.md_provsize = g_get_mediasize(name);
 	if (md.md_provsize == 0) {

Lucas Holt
Luke at FoolishGames.com
________________________________________________________
MidnightBSD.org (Free OS)
JustJournal.com (Free blogging)






More information about the freebsd-hackers mailing list