xref: /dflybsd-src/lib/libc/gen/fmtcheck.3 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
2*86d7f5d3SJohn Marino.\" All rights reserved.
3*86d7f5d3SJohn Marino.\"
4*86d7f5d3SJohn Marino.\" This file was contributed to The NetBSD Foundation by Allen Briggs.
5*86d7f5d3SJohn Marino.\"
6*86d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without
7*86d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions
8*86d7f5d3SJohn Marino.\" are met:
9*86d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright
10*86d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer.
11*86d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright
12*86d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer in the
13*86d7f5d3SJohn Marino.\"    documentation and/or other materials provided with the distribution.
14*86d7f5d3SJohn Marino.\" 3. All advertising materials mentioning features or use of this software
15*86d7f5d3SJohn Marino.\"    must display the following acknowledgement:
16*86d7f5d3SJohn Marino.\"        This product includes software developed by the NetBSD
17*86d7f5d3SJohn Marino.\"        Foundation, Inc. and its contributors.
18*86d7f5d3SJohn Marino.\" 4. Neither the name of The NetBSD Foundation nor the names of its
19*86d7f5d3SJohn Marino.\"    contributors may be used to endorse or promote products derived
20*86d7f5d3SJohn Marino.\"    from this software without specific prior written permission.
21*86d7f5d3SJohn Marino.\"
22*86d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23*86d7f5d3SJohn Marino.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24*86d7f5d3SJohn Marino.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25*86d7f5d3SJohn Marino.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26*86d7f5d3SJohn Marino.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27*86d7f5d3SJohn Marino.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28*86d7f5d3SJohn Marino.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29*86d7f5d3SJohn Marino.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30*86d7f5d3SJohn Marino.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31*86d7f5d3SJohn Marino.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32*86d7f5d3SJohn Marino.\" POSSIBILITY OF SUCH DAMAGE.
33*86d7f5d3SJohn Marino.\"
34*86d7f5d3SJohn Marino.\" $FreeBSD: src/lib/libc/gen/fmtcheck.3,v 1.10 2008/08/02 06:02:42 das Exp $
35*86d7f5d3SJohn Marino.\"
36*86d7f5d3SJohn Marino.Dd October 16, 2002
37*86d7f5d3SJohn Marino.Dt FMTCHECK 3
38*86d7f5d3SJohn Marino.Os
39*86d7f5d3SJohn Marino.Sh NAME
40*86d7f5d3SJohn Marino.Nm fmtcheck
41*86d7f5d3SJohn Marino.Nd sanitizes user-supplied
42*86d7f5d3SJohn Marino.Xr printf 3 Ns -style
43*86d7f5d3SJohn Marinoformat string
44*86d7f5d3SJohn Marino.Sh LIBRARY
45*86d7f5d3SJohn Marino.Lb libc
46*86d7f5d3SJohn Marino.Sh SYNOPSIS
47*86d7f5d3SJohn Marino.In stdio.h
48*86d7f5d3SJohn Marino.Ft const char *
49*86d7f5d3SJohn Marino.Fn fmtcheck "const char *fmt_suspect" "const char *fmt_default"
50*86d7f5d3SJohn Marino.Sh DESCRIPTION
51*86d7f5d3SJohn MarinoThe
52*86d7f5d3SJohn Marino.Fn fmtcheck
53*86d7f5d3SJohn Marinoscans
54*86d7f5d3SJohn Marino.Fa fmt_suspect
55*86d7f5d3SJohn Marinoand
56*86d7f5d3SJohn Marino.Fa fmt_default
57*86d7f5d3SJohn Marinoto determine if
58*86d7f5d3SJohn Marino.Fa fmt_suspect
59*86d7f5d3SJohn Marinowill consume the same argument types as
60*86d7f5d3SJohn Marino.Fa fmt_default
61*86d7f5d3SJohn Marinoand to ensure that
62*86d7f5d3SJohn Marino.Fa fmt_suspect
63*86d7f5d3SJohn Marinois a valid format string.
64*86d7f5d3SJohn Marino.Pp
65*86d7f5d3SJohn MarinoThe
66*86d7f5d3SJohn Marino.Xr printf 3
67*86d7f5d3SJohn Marinofamily of functions cannot verify the types of arguments that they are
68*86d7f5d3SJohn Marinopassed at run-time.
69*86d7f5d3SJohn MarinoIn some cases, like
70*86d7f5d3SJohn Marino.Xr catgets 3 ,
71*86d7f5d3SJohn Marinoit is useful or necessary to use a user-supplied format string with no
72*86d7f5d3SJohn Marinoguarantee that the format string matches the specified arguments.
73*86d7f5d3SJohn Marino.Pp
74*86d7f5d3SJohn MarinoThe
75*86d7f5d3SJohn Marino.Fn fmtcheck
76*86d7f5d3SJohn Marinowas designed to be used in these cases, as in:
77*86d7f5d3SJohn Marino.Bd -literal -offset indent
78*86d7f5d3SJohn Marinoprintf(fmtcheck(user_format, standard_format), arg1, arg2);
79*86d7f5d3SJohn Marino.Ed
80*86d7f5d3SJohn Marino.Pp
81*86d7f5d3SJohn MarinoIn the check, field widths, fillers, precisions, etc.\& are ignored (unless
82*86d7f5d3SJohn Marinothe field width or precision is an asterisk
83*86d7f5d3SJohn Marino.Ql *
84*86d7f5d3SJohn Marinoinstead of a digit string).
85*86d7f5d3SJohn MarinoAlso, any text other than the format specifiers
86*86d7f5d3SJohn Marinois completely ignored.
87*86d7f5d3SJohn Marino.Sh RETURN VALUES
88*86d7f5d3SJohn MarinoIf
89*86d7f5d3SJohn Marino.Fa fmt_suspect
90*86d7f5d3SJohn Marinois a valid format and consumes the same argument types as
91*86d7f5d3SJohn Marino.Fa fmt_default ,
92*86d7f5d3SJohn Marinothen the
93*86d7f5d3SJohn Marino.Fn fmtcheck
94*86d7f5d3SJohn Marinowill return
95*86d7f5d3SJohn Marino.Fa fmt_suspect .
96*86d7f5d3SJohn MarinoOtherwise, it will return
97*86d7f5d3SJohn Marino.Fa fmt_default .
98*86d7f5d3SJohn Marino.Sh SECURITY CONSIDERATIONS
99*86d7f5d3SJohn MarinoNote that the formats may be quite different as long as they accept the
100*86d7f5d3SJohn Marinosame arguments.
101*86d7f5d3SJohn MarinoFor example,
102*86d7f5d3SJohn Marino.Qq Li "%p %o %30s %#llx %-10.*e %n"
103*86d7f5d3SJohn Marinois compatible with
104*86d7f5d3SJohn Marino.Qq Li "This number %lu %d%% and string %s has %qd numbers and %.*g floats (%n)" .
105*86d7f5d3SJohn MarinoHowever,
106*86d7f5d3SJohn Marino.Qq Li %o
107*86d7f5d3SJohn Marinois not equivalent to
108*86d7f5d3SJohn Marino.Qq Li %lx
109*86d7f5d3SJohn Marinobecause
110*86d7f5d3SJohn Marinothe first requires an integer and the second requires a long.
111*86d7f5d3SJohn Marino.Sh SEE ALSO
112*86d7f5d3SJohn Marino.Xr printf 3
113*86d7f5d3SJohn Marino.Sh BUGS
114*86d7f5d3SJohn MarinoThe
115*86d7f5d3SJohn Marino.Fn fmtcheck
116*86d7f5d3SJohn Marinofunction does not recognize positional parameters.
117