Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Dec 2005 09:40:29 +0100
From:      "Poul-Henning Kamp" <phk@phk.freebsd.dk>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        Max Laier <max@love2party.net>, freebsd-arch@freebsd.org
Subject:   Re: printf behaviour with illegal or malformed format string 
Message-ID:  <9880.1134463229@critter.freebsd.dk>
In-Reply-To: Your message of "Tue, 13 Dec 2005 18:53:15 %2B1100." <20051213175413.H80942@delplex.bde.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <20051213175413.H80942@delplex.bde.org>, Bruce Evans writes:

>There is also fmtcheck(3).

I didn't even know about that one, but given that there is only two
uses in all of /src I do not feel ashamed.

>Extensions should rarely be needed for printf(),

Actually I disagree with you on that.

It was my list of "things I keep doing over and over" that convinced
me otherwise.

Here are some of the formats I miss, and which I will probably write
extensions for so people can trivially enable them:

	%T	print a time_t
	%lT	print a struct timeval
	%llT	print a struct timespec
	%I	print an IP#
	%lI	print an IPv6#
	%H	Hexdump
	%V	stringvis a string
	%M	Metric (like the "engineering" format on HP calculators)
	%H	"Human" (Tera,Giga,Mega,Kilo{bits,bytes})

>>> I'm leaning towards doing what phkmalloc has migrated to over time:
>>> Make a variable which can select between "normal/paranoia" and force
>>> it to paranoia for (uid==0 || gid==0 || setuid || setgid).
>>>
>>> If the variable is set, a bogus format string will result in abort(2).
>
>This sometimes breaks defined behaviour.

It does ?  I didn't think there were defined behaviour for bogus
format strings ?

>>> If it is not set, the format string will be output unformatted in
>>> the message "WARNING: Illegal printf() format string: \"...\".
>
>malloc()'s messages are better ("<progname>: error ...").

Obviously.


-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9880.1134463229>