Checking the return code of strlcpy won't say if the entire string fit 
(exactly) correctly, or if it was truncated. I think explicitly checking the 
length of label first is cleaner and more correct. 

I would, however, replace "15" with "sizeof(md.md_label) - 1" both in the check 
and the printf.

 ...................................
Andrew Duane
Juniper Networks
o   +1 978 589 0551
m  +1 603-770-7088
adu...@juniper.net

 


> -----Original Message-----
> From: owner-freebsd-hack...@freebsd.org [mailto:owner-freebsd-
> hack...@freebsd.org] On Behalf Of Ed Schouten
> Sent: Tuesday, November 08, 2011 6:34 AM
> To: Lucas Holt
> Cc: rank1see...@gmail.com; hack...@freebsd.org
> Subject: Re: BUG: 'glabel label' name's lenght, is truncated without
> err/warn
> 
> * Lucas Holt <l...@foolishgames.com>, 20111105 15:24:
> > --- 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) {
> 
> Why not simply perform the strlcpy and check whether
> 
>       if (strlcpy(...) >= sizeof(md.md_label)
> 
> ?
> 
> --
>  Ed Schouten <e...@80386.nl>
>  WWW: http://80386.nl/
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Reply via email to