From owner-freebsd-hackers@FreeBSD.ORG Tue Nov 8 15:42:12 2011 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 172081065673 for ; Tue, 8 Nov 2011 15:42:12 +0000 (UTC) (envelope-from aduane@juniper.net) Received: from exprod7og125.obsmtp.com (exprod7og125.obsmtp.com [64.18.2.28]) by mx1.freebsd.org (Postfix) with ESMTP id B98958FC08 for ; Tue, 8 Nov 2011 15:42:11 +0000 (UTC) Received: from P-EMHUB02-HQ.jnpr.net ([66.129.224.36]) (using TLSv1) by exprod7ob125.postini.com ([64.18.6.12]) with SMTP; Tue, 08 Nov 2011 07:42:11 PST Received: from p-emfe01-wf.jnpr.net (172.28.145.24) by P-EMHUB02-HQ.jnpr.net (172.24.192.36) with Microsoft SMTP Server (TLS) id 8.3.213.0; Tue, 8 Nov 2011 07:22:11 -0800 Received: from EMBX01-WF.jnpr.net ([fe80::1914:3299:33d9:e43b]) by p-emfe01-wf.jnpr.net ([fe80::d0d1:653d:5b91:a123%11]) with mapi; Tue, 8 Nov 2011 10:22:10 -0500 From: Andrew Duane To: Ed Schouten , Lucas Holt Date: Tue, 8 Nov 2011 10:22:09 -0500 Thread-Topic: BUG: 'glabel label' name's lenght, is truncated without err/warn Thread-Index: AcyeDNoJ2+/g+OgQRmWXvUFbC7g84QAHRQ8w Message-ID: References: <20111105.110247.867.1@DOMY-PC> <1859A0FF-C3BF-4EC3-9CC6-FA97B9AF5C99@foolishgames.com> <20111108113349.GG2258@hoeg.nl> In-Reply-To: <20111108113349.GG2258@hoeg.nl> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "rank1seeker@gmail.com" , "hackers@freebsd.org" Subject: RE: BUG: 'glabel label' name's lenght, is truncated without err/warn X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Nov 2011 15:42:12 -0000 Checking the return code of strlcpy won't say if the entire string fit (exa= ctly) correctly, or if it was truncated. I think explicitly checking the le= ngth of label first is cleaner and more correct.=20 I would, however, replace "15" with "sizeof(md.md_label) - 1" both in the c= heck and the printf. =A0................................... Andrew Duane Juniper Networks o=A0=A0=A0+1 978 589 0551 m=A0 +1 603-770-7088 aduane@juniper.net =A0 > -----Original Message----- > From: owner-freebsd-hackers@freebsd.org [mailto:owner-freebsd- > hackers@freebsd.org] On Behalf Of Ed Schouten > Sent: Tuesday, November 08, 2011 6:34 AM > To: Lucas Holt > Cc: rank1seeker@gmail.com; hackers@freebsd.org > Subject: Re: BUG: 'glabel label' name's lenght, is truncated without > err/warn >=20 > * Lucas Holt , 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 =3D 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 =3D G_LABEL_VERSION; > > - label =3D gctl_get_ascii(req, "arg0"); > > strlcpy(md.md_label, label, sizeof(md.md_label)); > > md.md_provsize =3D g_get_mediasize(name); > > if (md.md_provsize =3D=3D 0) { >=20 > Why not simply perform the strlcpy and check whether >=20 > if (strlcpy(...) >=3D sizeof(md.md_label) >=20 > ? >=20 > -- > Ed Schouten > WWW: http://80386.nl/