From owner-freebsd-arch Thu Dec 14 20:20:31 2000 From owner-freebsd-arch@FreeBSD.ORG Thu Dec 14 20:20:29 2000 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from sr14.nsw-remote.bigpond.net.au (sr14.nsw-remote.bigpond.net.au [24.192.3.29]) by hub.freebsd.org (Postfix) with ESMTP id 1428437B402 for ; Thu, 14 Dec 2000 20:20:27 -0800 (PST) Received: from areilly.bpc-users.org (CPE-144-132-234-126.nsw.bigpond.net.au [144.132.234.126]) by sr14.nsw-remote.bigpond.net.au (Pro-8.9.3/8.9.3) with SMTP id PAA28862 for ; Fri, 15 Dec 2000 15:20:20 +1100 (EDT) Received: (qmail 15037 invoked by uid 1000); 15 Dec 2000 04:20:18 -0000 From: "Andrew Reilly" Date: Fri, 15 Dec 2000 15:20:17 +1100 To: Terry Lambert Cc: Poul-Henning Kamp , kris@citusc.usc.edu, Dag-Erling Smorgrav , arch@FreeBSD.ORG Subject: Re: Safe string formatting in the kernel Message-ID: <20001215152017.A14921@gurney.reilly.home> References: <79446.976697492@critter> <200012130906.CAA27235@usr08.primenet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200012130906.CAA27235@usr08.primenet.com>; from tlambert@primenet.com on Wed, Dec 13, 2000 at 09:06:07AM +0000 Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Wed, Dec 13, 2000 at 09:06:07AM +0000, Terry Lambert wrote: > This would let you do the allocation based on peeking at the > size prior to copying the whole string in. Count prefix strings > are one thing the C language has been missing for years. Counted strings are good (lets you put arbitrary binary data into them, for one thing). Putting the count into a control structure as has been suggested here, or passed as another (separate) argument are both also good. Mangling the malloc'd data block so that the first word is a length, irrespective of whatever the data type is, is doubleplus ungood. (That mightn't have been what you meant by count _prefix_ strings, and I apologise if it wasn't, but it sounded like it to me.) -- Andrew To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message