1*be04fec4SKyle Evans.\" $NetBSD: ssp.3,v 1.9 2015/12/03 13:11:45 christos Exp $ 2*be04fec4SKyle Evans.\" 3*be04fec4SKyle Evans.\" SPDX-License-Identifier: BSD-2-Clause 4*be04fec4SKyle Evans.\" 5*be04fec4SKyle Evans.\" Copyright (c) 2007 The NetBSD Foundation, Inc. 6*be04fec4SKyle Evans.\" All rights reserved. 7*be04fec4SKyle Evans.\" 8*be04fec4SKyle Evans.\" This code is derived from software contributed to The NetBSD Foundation 9*be04fec4SKyle Evans.\" by Christos Zoulas. 10*be04fec4SKyle Evans.\" 11*be04fec4SKyle Evans.\" Redistribution and use in source and binary forms, with or without 12*be04fec4SKyle Evans.\" modification, are permitted provided that the following conditions 13*be04fec4SKyle Evans.\" are met: 14*be04fec4SKyle Evans.\" 1. Redistributions of source code must retain the above copyright 15*be04fec4SKyle Evans.\" notice, this list of conditions and the following disclaimer. 16*be04fec4SKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright 17*be04fec4SKyle Evans.\" notice, this list of conditions and the following disclaimer in the 18*be04fec4SKyle Evans.\" documentation and/or other materials provided with the distribution. 19*be04fec4SKyle Evans.\" 20*be04fec4SKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21*be04fec4SKyle Evans.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22*be04fec4SKyle Evans.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23*be04fec4SKyle Evans.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24*be04fec4SKyle Evans.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25*be04fec4SKyle Evans.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26*be04fec4SKyle Evans.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27*be04fec4SKyle Evans.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28*be04fec4SKyle Evans.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29*be04fec4SKyle Evans.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30*be04fec4SKyle Evans.\" POSSIBILITY OF SUCH DAMAGE. 31*be04fec4SKyle Evans.\" 32*be04fec4SKyle Evans.\" 33*be04fec4SKyle Evans.Dd December 3, 2015 34*be04fec4SKyle Evans.Dt SSP 3 35*be04fec4SKyle Evans.Os 36*be04fec4SKyle Evans.Sh NAME 37*be04fec4SKyle Evans.Nm ssp 38*be04fec4SKyle Evans.Nd bounds checked libc functions 39*be04fec4SKyle Evans.Sh LIBRARY 40*be04fec4SKyle Evans.Lb libssp 41*be04fec4SKyle Evans.Sh SYNOPSIS 42*be04fec4SKyle Evans.In ssp/stdio.h 43*be04fec4SKyle Evans.Ft int 44*be04fec4SKyle Evans.Fn sprintf "char *str" "const char *fmt" "..." 45*be04fec4SKyle Evans.Ft int 46*be04fec4SKyle Evans.Fn vsprintf "char *str" "const char *fmt" "va_list ap" 47*be04fec4SKyle Evans.Ft int 48*be04fec4SKyle Evans.Fn snprintf "char *str" "size_t len" "const char *fmt" "..." 49*be04fec4SKyle Evans.Ft int 50*be04fec4SKyle Evans.Fn vsnprintf "char *str" "size_t len" "const char *fmt" "va_list ap" 51*be04fec4SKyle Evans.Ft char * 52*be04fec4SKyle Evans.Fn fgets "char *str" "int len" "FILE *fp" 53*be04fec4SKyle Evans.In ssp/string.h 54*be04fec4SKyle Evans.Ft void * 55*be04fec4SKyle Evans.Fn memcpy "void *str" "const void *ptr" "size_t len" 56*be04fec4SKyle Evans.Ft void * 57*be04fec4SKyle Evans.Fn memmove "void *str" "const void *ptr" "size_t len" 58*be04fec4SKyle Evans.Ft void * 59*be04fec4SKyle Evans.Fn memset "void *str" "int val" "size_t len" 60*be04fec4SKyle Evans.Ft char * 61*be04fec4SKyle Evans.Fn stpcpy "char *str" "const char *ptr" 62*be04fec4SKyle Evans.Ft char * 63*be04fec4SKyle Evans.Fn strcpy "char *str" "const char *ptr" 64*be04fec4SKyle Evans.Ft char * 65*be04fec4SKyle Evans.Fn strcat "char *str" "const char *ptr" 66*be04fec4SKyle Evans.Ft char * 67*be04fec4SKyle Evans.Fn strncpy "char *str" "const char *ptr" "size_t len" 68*be04fec4SKyle Evans.Ft char * 69*be04fec4SKyle Evans.Fn strncat "char *str" "const char *ptr" "size_t len" 70*be04fec4SKyle Evans.In ssp/strings.h 71*be04fec4SKyle Evans.Ft void * 72*be04fec4SKyle Evans.Fn bcopy "const void *ptr" "void *str" "size_t len" 73*be04fec4SKyle Evans.Ft void * 74*be04fec4SKyle Evans.Fn bzero "void *str" "size_t len" 75*be04fec4SKyle Evans.In ssp/unistd.h 76*be04fec4SKyle Evans.Ft ssize_t 77*be04fec4SKyle Evans.Fn read "int fd" "void *str" "size_t len" 78*be04fec4SKyle Evans.Ft int 79*be04fec4SKyle Evans.Fn readlink "const char * restrict path" "char * restrict str" "size_t len" 80*be04fec4SKyle Evans.Ft int 81*be04fec4SKyle Evans.Fn getcwd "char *str" "size_t len" 82*be04fec4SKyle Evans.Sh DESCRIPTION 83*be04fec4SKyle EvansWhen 84*be04fec4SKyle Evans.Dv _FORTIFY_SOURCE 85*be04fec4SKyle Evansbounds checking is enabled as described below, the above functions get 86*be04fec4SKyle Evansoverwritten to use the 87*be04fec4SKyle Evans.Xr __builtin_object_size 3 88*be04fec4SKyle Evansfunction to compute the size of 89*be04fec4SKyle Evans.Fa str , 90*be04fec4SKyle Evansif known at compile time, 91*be04fec4SKyle Evansand perform bounds check on it in order 92*be04fec4SKyle Evansto avoid data buffer or stack buffer overflows. 93*be04fec4SKyle EvansIf an overflow is detected, the routines will call 94*be04fec4SKyle Evans.Xr abort 3 . 95*be04fec4SKyle Evans.Pp 96*be04fec4SKyle EvansTo enable these function overrides the following should be added to the 97*be04fec4SKyle Evans.Xr clang 1 98*be04fec4SKyle Evansor 99*be04fec4SKyle Evans.Xr gcc 1 100*be04fec4SKyle Evanscommand line: 101*be04fec4SKyle Evans.Dq \-D_FORTIFY_SOURCE=1 102*be04fec4SKyle Evansor 103*be04fec4SKyle Evans.Dq \-D_FORTIFY_SOURCE=2 . 104*be04fec4SKyle Evans.Pp 105*be04fec4SKyle EvansIf 106*be04fec4SKyle Evans.Dv _FORTIFY_SOURCE is set to 107*be04fec4SKyle Evans.Dv 1 108*be04fec4SKyle Evansthe code will compute the maximum possible buffer size for 109*be04fec4SKyle Evans.Fa str , 110*be04fec4SKyle Evansand if set to 111*be04fec4SKyle Evans.Dv 2 112*be04fec4SKyle Evansit will compute the minimum buffer size. 113*be04fec4SKyle Evans.Sh SEE ALSO 114*be04fec4SKyle Evans.Xr clang 1 , 115*be04fec4SKyle Evans.Xr gcc 1 , 116*be04fec4SKyle Evans.Xr __builtin_object_size 3 , 117*be04fec4SKyle Evans.Xr stdio 3 , 118*be04fec4SKyle Evans.Xr string 3 , 119*be04fec4SKyle Evans.Xr security 7 120*be04fec4SKyle Evans.Sh HISTORY 121*be04fec4SKyle EvansThe 122*be04fec4SKyle Evans.Nm 123*be04fec4SKyle Evanslibrary appeared in 124*be04fec4SKyle Evans.Nx 4.0 . 125*be04fec4SKyle EvansThis version of the 126*be04fec4SKyle Evans.Nm 127*be04fec4SKyle Evanslibrary replaced the GNU library of the same name in 128*be04fec4SKyle Evans.Fx 12.2 . 129