t_ssp.sh revision 1.1 1 # $NetBSD: t_ssp.sh,v 1.1 2010/12/27 02:04:19 pgoyette Exp $
2 #
3 # Copyright (c) 2008 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 h_pass()
29 {
30 echo "Executing command [ $1 ]"
31 atf_check -s exit:0 -o ignore -e ignore $1
32 }
33
34 h_fail()
35 {
36 echo "Executing command [ $1 ]"
37 atf_check -s signal:6 -o ignore -e ignore $1
38 }
39
40 atf_test_case raw
41 raw_head()
42 {
43 atf_set "descr" "Checks basic stack protection"
44 }
45 raw_body()
46 {
47 prog="$(atf_get_srcdir)/h_raw"
48
49 h_pass "$prog 9"
50 h_fail "$prog 10"
51 }
52
53 atf_test_case sprintf
54 sprintf_head()
55 {
56 atf_set "descr" "Checks sprintf(3)"
57 }
58 sprintf_body()
59 {
60 prog="$(atf_get_srcdir)/h_sprintf"
61
62 h_pass "$prog ok"
63 h_fail "$prog 0123456789"
64 }
65
66 atf_test_case vsprintf
67 vsprintf_head()
68 {
69 atf_set "descr" "Checks vsprintf(3)"
70 }
71 vsprintf_body()
72 {
73 prog="$(atf_get_srcdir)/h_vsprintf"
74
75 h_pass "$prog ok"
76 h_fail "$prog 0123456789"
77 }
78
79 atf_test_case snprintf
80 snprintf_head()
81 {
82 atf_set "descr" "Checks snprintf(3)"
83 }
84 snprintf_body()
85 {
86 prog="$(atf_get_srcdir)/h_snprintf"
87
88 h_pass "$prog 10"
89 h_fail "$prog 11"
90 }
91
92 atf_test_case vsnprintf
93 vsnprintf_head()
94 {
95 atf_set "descr" "Checks vsnprintf(3)"
96 }
97 vsnprintf_body()
98 {
99 prog="$(atf_get_srcdir)/h_vsnprintf"
100
101 h_pass "$prog 10"
102 h_fail "$prog 11"
103 }
104
105 atf_test_case gets
106 gets_head()
107 {
108 atf_set "descr" "Checks gets(3)"
109 }
110 gets_body()
111 {
112 prog="$(atf_get_srcdir)/h_gets"
113
114 h_pass "echo ok | $prog"
115 h_fail "echo 0123456789 | $prog"
116 }
117
118 atf_test_case fgets
119 fgets_head()
120 {
121 atf_set "descr" "Checks fgets(3)"
122 }
123 fgets_body()
124 {
125 prog="$(atf_get_srcdir)/h_fgets"
126
127 h_pass "echo ok | $prog 10"
128 h_fail "echo busted | $prog 11"
129 }
130
131 atf_test_case memcpy
132 memcpy_head()
133 {
134 atf_set "descr" "Checks memcpy(3)"
135 }
136 memcpy_body()
137 {
138 prog="$(atf_get_srcdir)/h_memcpy"
139
140 h_pass "$prog 10"
141 h_fail "$prog 11"
142 }
143
144 atf_test_case memmove
145 memmove_head()
146 {
147 atf_set "descr" "Checks memmove(3)"
148 }
149 memmove_body()
150 {
151 prog="$(atf_get_srcdir)/h_memmove"
152
153 h_pass "$prog 10"
154 h_fail "$prog 11"
155 }
156
157 atf_test_case memset
158 memset_head()
159 {
160 atf_set "descr" "Checks memset(3)"
161 }
162 memset_body()
163 {
164 prog="$(atf_get_srcdir)/h_memset"
165
166 h_pass "$prog 10"
167 h_fail "$prog 11"
168 }
169
170 atf_test_case strcpy
171 strcpy_head()
172 {
173 atf_set "descr" "Checks strcpy(3)"
174 }
175 strcpy_body()
176 {
177 prog="$(atf_get_srcdir)/h_strcpy"
178
179 h_pass "$prog 0123456"
180 h_fail "$prog 0123456789"
181 }
182
183 atf_test_case strcat
184 strcat_head()
185 {
186 atf_set "descr" "Checks strcat(3)"
187 }
188 strcat_body()
189 {
190 prog="$(atf_get_srcdir)/h_strcat"
191
192 h_pass "$prog 0123456"
193 h_fail "$prog 012345678"
194 }
195
196 atf_test_case strncpy
197 strncpy_head()
198 {
199 atf_set "descr" "Checks strncpy(3)"
200 }
201 strncpy_body()
202 {
203 prog="$(atf_get_srcdir)/h_strncpy"
204
205 h_pass "$prog 10"
206 h_fail "$prog 11"
207 }
208
209 atf_test_case strncat
210 strncat_head()
211 {
212 atf_set "descr" "Checks strncat(3)"
213 }
214 strncat_body()
215 {
216 prog="$(atf_get_srcdir)/h_strncat"
217
218 h_pass "$prog 8"
219 h_fail "$prog 9"
220 }
221
222 atf_test_case read
223 read_head()
224 {
225 atf_set "descr" "Checks read(2)"
226 }
227 read_body()
228 {
229 prog="$(atf_get_srcdir)/h_read"
230
231 h_pass "echo foo | $prog 1024"
232 h_fail "echo bar | $prog 1025"
233 }
234
235 atf_test_case readlink
236 readlink_head()
237 {
238 atf_set "descr" "Checks readlink(2)"
239 }
240 readlink_body()
241 {
242 prog="$(atf_get_srcdir)/h_readlink"
243
244 h_pass "$prog 1024"
245 h_fail "$prog 1025"
246 }
247
248 atf_test_case getcwd
249 getcwd_head()
250 {
251 atf_set "descr" "Checks getcwd(3)"
252 }
253 getcwd_body()
254 {
255 prog="$(atf_get_srcdir)/h_getcwd"
256
257 h_pass "$prog 1024"
258 h_fail "$prog 1025"
259 }
260
261 atf_init_test_cases()
262 {
263 atf_add_test_case raw
264 atf_add_test_case sprintf
265 atf_add_test_case vsprintf
266 atf_add_test_case snprintf
267 atf_add_test_case vsnprintf
268 atf_add_test_case gets
269 atf_add_test_case fgets
270 atf_add_test_case memcpy
271 atf_add_test_case memmove
272 atf_add_test_case memset
273 atf_add_test_case strcat
274 atf_add_test_case strcpy
275 atf_add_test_case strncat
276 atf_add_test_case strncpy
277 atf_add_test_case read
278 atf_add_test_case readlink
279 atf_add_test_case getcwd
280 }
281