1 .\" $NetBSD: ssp.3,v 1.3 2008/04/30 13:10:50 martin Exp $
3 .\" Copyright (c) 2007 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Christos Zoulas.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
36 .Nd bounds checked libc functions
42 .Fn sprintf "char *str" "const char *fmt" "..."
44 .Fn vsprintf "char *str" "const char *fmt" "va_list ap"
46 .Fn snprintf "char *str" "size_t len" "const char *fmt" "..."
48 .Fn vsnprintf "char *str" "size_t len" "const char *fmt" "va_list ap"
52 .Fn fgets "char *str" "int len" "FILE *fp"
55 .Fn memcpy "void *str" "const void *ptr" "size_t len"
57 .Fn memmove "void *str" "const void *ptr" "size_t len"
59 .Fn memset "void *str" "int val" "size_t len"
61 .Fn strcpy "char *str" "const char *ptr" "size_t len"
63 .Fn strcat "char *str" "const char *ptr" "size_t len"
65 .Fn strncpy "char *str" "const char *ptr" "size_t len"
67 .Fn strncat "char *str" "const char *ptr" "size_t len"
70 .Fn bcopy "const void *ptr" "void *str" "size_t len"
72 .Fn bzero "void *str" "size_t len"
75 .Fn read "int fd" "void *str" "size_t len"
77 .Fn readlink "const char * restrict path" "char * restrict str" "size_t len"
79 .Fn getcwd "char *str" "size_t len"
83 bounds checking is enabled as described below, the above functions get
84 overwritten to use the
86 .Xr __builtin_object_size 3
87 function to compute the size of
89 if known at compile time and perform bounds check on it in order
90 to avoid data buffer or stack buffer overflows.
91 If an overflow is detected the routines will call
94 To enable these function overrides the following should be added to the
97 .Dq \-I/usr/include/ssp
98 to override the standard include files and
99 .Dq \-D_FORTIFY_SOURCE=1
101 .Dq \-D_FORTIFY_SOURCE=2 .
104 .Dv _FORTIFY_SOURCE is set to
106 the code will compute the maximum possible buffer size for
110 it will compute the minimum buffer size.
115 .Xr __builtin_object_size 3 ,