1FMTCHECK(3)              BSD Library Functions Manual              FMTCHECK(3)
2

NAME

4     fmtcheck — sanitizes user-supplied printf(3)-style format string
5

LIBRARY

7     Utility functions from BSD systems (libbsd, -lbsd)
8

SYNOPSIS

10     #include <stdio.h>
11
12     const char *
13     fmtcheck(const char *fmt_suspect, const char *fmt_default);
14

DESCRIPTION

16     The fmtcheck() scans fmt_suspect and fmt_default to determine if
17     fmt_suspect will consume the same argument types as fmt_default and to
18     ensure that fmt_suspect is a valid format string.
19
20     The printf(3) family of functions cannot verify the types of arguments
21     that they are passed at run-time.  In some cases, like catgets(3), it is
22     useful or necessary to use a user-supplied format string with no guaran‐
23     tee that the format string matches the specified arguments.
24
25     The fmtcheck() was designed to be used in these cases, as in:
26
27           printf(fmtcheck(user_format, standard_format), arg1, arg2);
28
29     In the check, field widths, fillers, precisions, etc. are ignored (unless
30     the field width or precision is an asterisk ‘*’ instead of a digit
31     string).  Also, any text other than the format specifiers is completely
32     ignored.
33

RETURN VALUES

35     If fmt_suspect is a valid format and consumes the same argument types as
36     fmt_default, then the fmtcheck() will return fmt_suspect.  Otherwise, it
37     will return fmt_default.
38

SECURITY CONSIDERATIONS

40     Note that the formats may be quite different as long as they accept the
41     same arguments.  For example, "%p %o %30s %#llx %-10.*e %n" is compatible
42     with "This number %lu %d%% and string %s has %qd numbers and %.*g floats
43     (%n)".  However, "%o" is not equivalent to "%lx" because the first
44     requires an integer and the second requires a long.
45

SEE ALSO

47     printf(3)
48

BUGS

50     The fmtcheck() function does not understand all of the conversions that
51     printf(3) does.
52
53BSD                            October 16, 2002                            BSD
Impressum