2 * Copyright (c) 2017 Juniper Networks. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
37 static const char * restrict m;
40 h(const char * restrict msg, void * restrict ptr __unused, errno_t error)
47 ATF_TC_WITHOUT_HEAD(null_ptr);
48 ATF_TC_BODY(null_ptr, tc)
50 assert(memset_s(0, 1, 1, 1) != 0);
54 ATF_TC_WITHOUT_HEAD(smax_gt_rmax);
55 ATF_TC_BODY(smax_gt_rmax, tc)
59 assert(memset_s(&b, RSIZE_MAX + 1, 1, 1) != 0);
63 ATF_TC_WITHOUT_HEAD(smax_lt_zero);
64 ATF_TC_BODY(smax_lt_zero, tc)
68 assert(memset_s(&b, -1, 1, 1) != 0);
72 ATF_TC_WITHOUT_HEAD(normal);
73 ATF_TC_BODY(normal, tc)
78 assert(memset_s(&b, 1, 5, 1) == 0);
83 ATF_TC_WITHOUT_HEAD(n_gt_rmax);
84 ATF_TC_BODY(n_gt_rmax, tc)
88 assert(memset_s(&b, 1, 1, RSIZE_MAX + 1) != 0);
92 ATF_TC_WITHOUT_HEAD(n_lt_zero);
93 ATF_TC_BODY(n_lt_zero, tc)
97 assert(memset_s(&b, 1, 1, -1) != 0);
101 ATF_TC_WITHOUT_HEAD(n_lt_smax);
102 ATF_TC_BODY(n_lt_smax, tc)
104 char b[3] = {1, 2, 3};
106 assert(memset_s(&b[0], 3, 9, 1) == 0);
112 /* n > smax, handler */
113 ATF_TC_WITHOUT_HEAD(n_gt_smax);
114 ATF_TC_BODY(n_gt_smax, tc)
116 char b[3] = {1, 2, 3};
120 set_constraint_handler_s(h);
121 assert(memset_s(&b[0], 1, 9, 3) != 0);
123 assert(strcmp(m, "memset_s : n > smax") == 0);
129 /* smax > rmax, handler */
130 ATF_TC_WITHOUT_HEAD(smax_gt_rmax_handler);
131 ATF_TC_BODY(smax_gt_rmax_handler, tc)
137 set_constraint_handler_s(h);
138 assert(memset_s(&b, RSIZE_MAX + 1, 1, 1) != 0);
140 assert(strcmp(m, "memset_s : smax > RSIZE_MAX") == 0);
143 /* smax < 0, handler */
144 ATF_TC_WITHOUT_HEAD(smax_lt_zero_handler);
145 ATF_TC_BODY(smax_lt_zero_handler, tc)
151 set_constraint_handler_s(h);
152 assert(memset_s(&b, -1, 1, 1) != 0);
154 assert(strcmp(m, "memset_s : smax > RSIZE_MAX") == 0);
157 /* n > rmax, handler */
158 ATF_TC_WITHOUT_HEAD(n_gt_rmax_handler);
159 ATF_TC_BODY(n_gt_rmax_handler, tc)
165 set_constraint_handler_s(h);
166 assert(memset_s(&b, 1, 1, RSIZE_MAX + 1) != 0);
168 assert(strcmp(m, "memset_s : n > RSIZE_MAX") == 0);
172 ATF_TC_WITHOUT_HEAD(n_lt_zero_handler);
173 ATF_TC_BODY(n_lt_zero_handler, tc)
179 set_constraint_handler_s(h);
180 assert(memset_s(&b, 1, 1, -1) != 0);
182 assert(strcmp(m, "memset_s : n > RSIZE_MAX") == 0);
187 ATF_TP_ADD_TC(tp, null_ptr);
188 ATF_TP_ADD_TC(tp, smax_gt_rmax);
189 ATF_TP_ADD_TC(tp, smax_lt_zero);
190 ATF_TP_ADD_TC(tp, normal);
191 ATF_TP_ADD_TC(tp, n_gt_rmax);
192 ATF_TP_ADD_TC(tp, n_lt_zero);
193 ATF_TP_ADD_TC(tp, n_gt_smax);
194 ATF_TP_ADD_TC(tp, n_lt_smax);
195 ATF_TP_ADD_TC(tp, smax_gt_rmax_handler);
196 ATF_TP_ADD_TC(tp, smax_lt_zero_handler);
197 ATF_TP_ADD_TC(tp, n_gt_rmax_handler);
198 ATF_TP_ADD_TC(tp, n_lt_zero_handler);
199 return (atf_no_error());