t_ssp.sh revision 319486
1# $NetBSD: t_ssp.sh,v 1.7 2014/04/06 19:28:59 christos 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
28h_pass()
29{
30	echo "Executing command [ $2$1 ]"
31	eval $2 atf_check -s exit:0 -o ignore -e ignore $1
32}
33
34h_fail()
35{
36	echo "Executing command [ $2$1 ]"
37	# Begin FreeBSD
38	ulimit -c 0
39	if true; then
40		eval $2 atf_check -s signal -o ignore -e ignore $1
41	else
42	# End FreeBSD
43	eval $2 atf_check -s signal:6 -o ignore -e ignore $1
44	# Begin FreeBSD
45	fi
46	# End FreeBSD
47}
48
49atf_test_case sprintf
50sprintf_head()
51{
52	atf_set "descr" "Checks sprintf(3)"
53}
54sprintf_body()
55{
56	prog="$(atf_get_srcdir)/h_sprintf"
57
58	h_pass "$prog ok"
59	# Begin FreeBSD
60	if true; then
61		h_fail "$prog 0123456789ab"
62	else
63	# End FreeBSD
64	h_fail "$prog 0123456789"
65	# Begin FreeBSD
66	fi
67	# End FreeBSD
68}
69
70atf_test_case vsprintf
71vsprintf_head()
72{
73	atf_set "descr" "Checks vsprintf(3)"
74}
75vsprintf_body()
76{
77	prog="$(atf_get_srcdir)/h_vsprintf"
78
79	h_pass "$prog ok"
80	# Begin FreeBSD
81	if true; then
82		h_fail "$prog 0123456789ab"
83	else
84	# End FreeBSD
85	h_fail "$prog 0123456789"
86	# Begin FreeBSD
87	fi
88	# End FreeBSD
89}
90
91atf_test_case snprintf
92snprintf_head()
93{
94	atf_set "descr" "Checks snprintf(3)"
95}
96snprintf_body()
97{
98	prog="$(atf_get_srcdir)/h_snprintf"
99
100	h_pass "$prog 10"
101	# Begin FreeBSD
102	if true; then
103		h_fail "$prog 13"
104	else
105	# End FreeBSD
106	h_fail "$prog 11"
107	# Begin FreeBSD
108	fi
109	# End FreeBSD
110}
111
112atf_test_case vsnprintf
113vsnprintf_head()
114{
115	atf_set "descr" "Checks vsnprintf(3)"
116}
117vsnprintf_body()
118{
119	prog="$(atf_get_srcdir)/h_vsnprintf"
120
121	h_pass "$prog 10"
122	# Begin FreeBSD
123	if true; then
124		h_fail "$prog 13"
125	else
126	# End FreeBSD
127	h_fail "$prog 11"
128	# Begin FreeBSD
129	fi
130	# End FreeBSD
131}
132
133atf_test_case gets
134gets_head()
135{
136	atf_set "descr" "Checks gets(3)"
137}
138gets_body()
139{
140	prog="$(atf_get_srcdir)/h_gets"
141
142	h_pass "$prog" "echo ok |"
143	# Begin FreeBSD
144	if true; then
145		h_fail "$prog" "echo 0123456789ab |"
146	else
147	# End FreeBSD
148	h_fail "$prog" "echo 0123456789 |"
149	# Begin FreeBSD
150	fi
151	# End FreeBSD
152}
153
154atf_test_case fgets
155fgets_head()
156{
157	atf_set "descr" "Checks fgets(3)"
158}
159fgets_body()
160{
161	prog="$(atf_get_srcdir)/h_fgets"
162
163	h_pass "$prog 10" "echo ok |"
164	# Begin FreeBSD
165	if true; then
166		h_fail "$prog 13" "echo 0123456789abc |"
167	else
168	# End FreeBSD
169	h_fail "$prog 11" "echo busted |"
170	# Begin FreeBSD
171	fi
172	# End FreeBSD
173}
174
175atf_test_case memcpy
176memcpy_head()
177{
178	atf_set "descr" "Checks memcpy(3)"
179}
180memcpy_body()
181{
182	prog="$(atf_get_srcdir)/h_memcpy"
183
184	h_pass "$prog 10"
185	# Begin FreeBSD
186	if true; then
187		h_fail "$prog 13"
188	else
189	# End FreeBSD
190	h_fail "$prog 11"
191	# Begin FreeBSD
192	fi
193	# End FreeBSD
194}
195
196atf_test_case memmove
197memmove_head()
198{
199	atf_set "descr" "Checks memmove(3)"
200}
201memmove_body()
202{
203	prog="$(atf_get_srcdir)/h_memmove"
204
205	h_pass "$prog 10"
206	# Begin FreeBSD
207	if true; then
208		h_fail "$prog 13"
209	else
210	# End FreeBSD
211	h_fail "$prog 11"
212	# Begin FreeBSD
213	fi
214	# End FreeBSD
215}
216
217atf_test_case memset
218memset_head()
219{
220	atf_set "descr" "Checks memset(3)"
221}
222memset_body()
223{
224	prog="$(atf_get_srcdir)/h_memset"
225
226	h_pass "$prog 10"
227	# Begin FreeBSD
228	if true; then
229		h_fail "$prog 13"
230	else
231	# End FreeBSD
232	h_fail "$prog 11"
233	# Begin FreeBSD
234	fi
235	# End FreeBSD
236}
237
238atf_test_case strcpy
239strcpy_head()
240{
241	atf_set "descr" "Checks strcpy(3)"
242}
243strcpy_body()
244{
245	prog="$(atf_get_srcdir)/h_strcpy"
246
247	h_pass "$prog 0123456"
248	# Begin FreeBSD
249	if true; then
250		h_fail "$prog 0123456789ab"
251	else
252	# End FreeBSD
253	h_fail "$prog 0123456789"
254	# Begin FreeBSD
255	fi
256	# End FreeBSD
257}
258
259atf_test_case stpcpy
260stpcpy_head()
261{
262	atf_set "descr" "Checks stpcpy(3)"
263}
264stpcpy_body()
265{
266	prog="$(atf_get_srcdir)/h_stpcpy"
267
268	h_pass "$prog 0123456"
269	# Begin FreeBSD
270	if true; then
271		h_fail "$prog 0123456789ab"
272	else
273	# End FreeBSD
274	h_fail "$prog 0123456789"
275	# Begin FreeBSD
276	fi
277	# End FreeBSD
278}
279
280atf_test_case strcat
281strcat_head()
282{
283	atf_set "descr" "Checks strcat(3)"
284}
285strcat_body()
286{
287	prog="$(atf_get_srcdir)/h_strcat"
288
289	h_pass "$prog 0123456"
290	h_fail "$prog 0123456789ABCDEF"
291}
292
293atf_test_case strncpy
294strncpy_head()
295{
296	atf_set "descr" "Checks strncpy(3)"
297}
298strncpy_body()
299{
300	prog="$(atf_get_srcdir)/h_strncpy"
301
302	h_pass "$prog 10"
303	# Begin FreeBSD
304	if true; then
305		h_fail "$prog 13"
306	else
307	# End FreeBSD
308	h_fail "$prog 11"
309	# Begin FreeBSD
310	fi
311	# End FreeBSD
312}
313
314atf_test_case stpncpy
315stpncpy_head()
316{
317	atf_set "descr" "Checks stpncpy(3)"
318}
319stpncpy_body()
320{
321	prog="$(atf_get_srcdir)/h_stpncpy"
322
323	h_pass "$prog 10"
324	# Begin FreeBSD
325	if true; then
326		h_fail "$prog 13"
327	else
328	# End FreeBSD
329	h_fail "$prog 11"
330	# Begin FreeBSD
331	fi
332	# End FreeBSD
333}
334
335atf_test_case strncat
336strncat_head()
337{
338	atf_set "descr" "Checks strncat(3)"
339}
340strncat_body()
341{
342	prog="$(atf_get_srcdir)/h_strncat"
343
344	# Begin FreeBSD
345	h_pass "$prog 8"
346	if true; then
347		h_fail "$prog 11"
348	else
349	# End FreeBSD
350	h_fail "$prog 9"
351	# Begin FreeBSD
352	fi
353	# End FreeBSD
354}
355
356atf_test_case raw
357raw_head()
358{
359	atf_set "descr" "Checks raw array overflow"
360}
361raw_body()
362{
363	prog="$(atf_get_srcdir)/h_raw"
364	# Begin FreeBSD
365	[ -x $prog ] || atf_skip "$prog is missing; skipping testcase"
366	# End FreeBSD
367
368	h_pass "$prog 9"
369	# Begin FreeBSD
370	if true; then
371		h_fail "$prog 12"
372	else
373	# End FreeBSD
374	h_fail "$prog 10"
375	# Begin FreeBSD
376	fi
377	# End FreeBSD
378}
379
380atf_test_case read
381read_head()
382{
383	atf_set "descr" "Checks read(2)"
384}
385read_body()
386{
387	prog="$(atf_get_srcdir)/h_read"
388
389	# Begin FreeBSD
390	if true; then
391	MAX_PATH=$(getconf _XOPEN_PATH_MAX) || atf_fail "getconf failed"
392	h_pass "$prog $MAX_PATH" "echo foo |"
393	h_fail "$prog $(( $MAX_PATH + 3 ))" "echo bar |"
394	else
395	# End FreeBSD
396	h_pass "$prog 1024" "echo foo |"
397	h_fail "$prog 1025" "echo bar |"
398	# Begin FreeBSD
399	fi
400	# End FreeBSD
401}
402
403atf_test_case readlink
404readlink_head()
405{
406	atf_set "descr" "Checks readlink(2)"
407}
408readlink_body()
409{
410	prog="$(atf_get_srcdir)/h_readlink"
411
412	# Begin FreeBSD
413	if true; then
414		h_pass "$prog 512"
415		h_fail "$prog 523"
416	else
417	# End FreeBSD
418	h_pass "$prog 1024"
419	h_fail "$prog 1025"
420	# Begin FreeBSD
421	fi
422	# End FreeBSD
423}
424
425atf_test_case getcwd
426getcwd_head()
427{
428	atf_set "descr" "Checks getcwd(3)"
429}
430getcwd_body()
431{
432	prog="$(atf_get_srcdir)/h_getcwd"
433
434	h_pass "$prog 1024"
435	# Begin FreeBSD
436	if false; then
437	# End FreeBSD
438	h_fail "$prog 1025"
439	# Begin FreeBSD
440	fi
441	# End FreeBSD
442}
443
444atf_init_test_cases()
445{
446	atf_add_test_case sprintf
447	atf_add_test_case vsprintf
448	atf_add_test_case snprintf
449	atf_add_test_case vsnprintf
450	atf_add_test_case gets
451	atf_add_test_case fgets
452	atf_add_test_case memcpy
453	atf_add_test_case memmove
454	atf_add_test_case memset
455	atf_add_test_case stpcpy
456	atf_add_test_case stpncpy
457	atf_add_test_case strcat
458	atf_add_test_case strcpy
459	atf_add_test_case strncat
460	atf_add_test_case strncpy
461	atf_add_test_case raw
462	atf_add_test_case read
463	atf_add_test_case readlink
464	atf_add_test_case getcwd
465}
466