xref: /freebsd/lib/libc/tests/secure/fortify_unistd_test.c (revision b670c9bafc0e31c7609969bf374b2e80bdc00211)
1 /* @generated by `generate-fortify-tests.lua "unistd"` */
2 
3 #define	_FORTIFY_SOURCE	2
4 #define	TMPFILE_SIZE	(1024 * 32)
5 
6 #include <sys/param.h>
7 #include <sys/jail.h>
8 #include <sys/random.h>
9 #include <sys/resource.h>
10 #include <sys/select.h>
11 #include <sys/socket.h>
12 #include <sys/time.h>
13 #include <sys/uio.h>
14 #include <sys/wait.h>
15 #include <dirent.h>
16 #include <errno.h>
17 #include <fcntl.h>
18 #include <limits.h>
19 #include <poll.h>
20 #include <signal.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <strings.h>
25 #include <sysexits.h>
26 #include <unistd.h>
27 #include <wchar.h>
28 #include <atf-c.h>
29 
30 static FILE * __unused
31 new_fp(size_t __len)
32 {
33 	static char fpbuf[LINE_MAX];
34 	FILE *fp;
35 
36 	ATF_REQUIRE(__len <= sizeof(fpbuf));
37 
38 	memset(fpbuf, 'A', sizeof(fpbuf) - 1);
39 	fpbuf[sizeof(fpbuf) - 1] = '\0';
40 
41 	fp = fmemopen(fpbuf, sizeof(fpbuf), "rb");
42 	ATF_REQUIRE(fp != NULL);
43 
44 	return (fp);
45 }
46 
47 /*
48  * Create a new symlink to use for readlink(2) style tests, we'll just use a
49  * random target name to have something interesting to look at.
50  */
51 static const char * __unused
52 new_symlink(size_t __len)
53 {
54 	static const char linkname[] = "link";
55 	char target[MAXNAMLEN];
56 	int error;
57 
58 	ATF_REQUIRE(__len <= sizeof(target));
59 
60 	arc4random_buf(target, sizeof(target));
61 
62 	error = unlink(linkname);
63 	ATF_REQUIRE(error == 0 || errno == ENOENT);
64 
65 	error = symlink(target, linkname);
66 	ATF_REQUIRE(error == 0);
67 
68 	return (linkname);
69 }
70 
71 /*
72  * For our purposes, first descriptor will be the reader; we'll send both
73  * raw data and a control message over it so that the result can be used for
74  * any of our recv*() tests.
75  */
76 static void __unused
77 new_socket(int sock[2])
78 {
79 	unsigned char ctrl[CMSG_SPACE(sizeof(int))] = { 0 };
80 	static char sockbuf[256];
81 	ssize_t rv;
82 	size_t total = 0;
83 	struct msghdr hdr = { 0 };
84 	struct cmsghdr *cmsg;
85 	int error, fd;
86 
87 	error = socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
88 	ATF_REQUIRE(error == 0);
89 
90 	while (total != sizeof(sockbuf)) {
91 		rv = send(sock[1], &sockbuf[total], sizeof(sockbuf) - total, 0);
92 
93 		ATF_REQUIRE_MSG(rv > 0,
94 		    "expected bytes sent, got %zd with %zu left (size %zu, total %zu)",
95 		    rv, sizeof(sockbuf) - total, sizeof(sockbuf), total);
96 		ATF_REQUIRE_MSG(total + (size_t)rv <= sizeof(sockbuf),
97 		    "%zd exceeds total %zu", rv, sizeof(sockbuf));
98 		total += rv;
99 	}
100 
101 	hdr.msg_control = ctrl;
102 	hdr.msg_controllen = sizeof(ctrl);
103 
104 	cmsg = CMSG_FIRSTHDR(&hdr);
105 	cmsg->cmsg_level = SOL_SOCKET;
106 	cmsg->cmsg_type = SCM_RIGHTS;
107 	cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
108 	fd = STDIN_FILENO;
109 	memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd));
110 
111 	error = sendmsg(sock[1], &hdr, 0);
112 	ATF_REQUIRE(error != -1);
113 }
114 
115 /*
116  * Constructs a tmpfile that we can use for testing read(2) and friends.
117  */
118 static int __unused
119 new_tmpfile(void)
120 {
121 	char buf[1024];
122 	ssize_t rv;
123 	size_t written;
124 	int fd;
125 
126 	fd = open("tmpfile", O_RDWR | O_CREAT | O_TRUNC, 0644);
127 	ATF_REQUIRE(fd >= 0);
128 
129 	written = 0;
130 	while (written < TMPFILE_SIZE) {
131 		rv = write(fd, buf, sizeof(buf));
132 		ATF_REQUIRE(rv > 0);
133 
134 		written += rv;
135 	}
136 
137 	ATF_REQUIRE_EQ(0, lseek(fd, 0, SEEK_SET));
138 	return (fd);
139 }
140 
141 static void
142 disable_coredumps(void)
143 {
144 	struct rlimit rl = { 0 };
145 
146 	if (setrlimit(RLIMIT_CORE, &rl) == -1)
147 		_exit(EX_OSERR);
148 }
149 
150 /*
151  * Replaces stdin with a file that we can actually read from, for tests where
152  * we want a FILE * or fd that we can get data from.
153  */
154 static void __unused
155 replace_stdin(void)
156 {
157 	int fd;
158 
159 	fd = new_tmpfile();
160 
161 	(void)dup2(fd, STDIN_FILENO);
162 	if (fd != STDIN_FILENO)
163 		close(fd);
164 }
165 
166 #define	JAIL_HOSTNAME	"host.example.com"
167 #define	JAIL_DOMAINNAME	"example.com"
168 static void
169 dhost_jail(void)
170 {
171 	struct iovec iov[4];
172 	int jid;
173 
174 	iov[0].iov_base = __DECONST(char *, "host.hostname");
175 	iov[0].iov_len = sizeof("host.hostname");
176 	iov[1].iov_base = __DECONST(char *, JAIL_HOSTNAME);
177 	iov[1].iov_len = sizeof(JAIL_HOSTNAME);
178 	iov[2].iov_base = __DECONST(char *, "host.domainname");
179 	iov[2].iov_len = sizeof("host.domainname");
180 	iov[3].iov_base = __DECONST(char *, JAIL_DOMAINNAME);
181 	iov[3].iov_len = sizeof(JAIL_DOMAINNAME);
182 
183 	jid = jail_set(iov, nitems(iov), JAIL_CREATE | JAIL_ATTACH);
184 	ATF_REQUIRE_MSG(jid > 0, "Jail creation failed: %s", strerror(errno));
185 }
186 
187 ATF_TC(getcwd_before_end);
188 ATF_TC_HEAD(getcwd_before_end, tc)
189 {
190 }
191 ATF_TC_BODY(getcwd_before_end, tc)
192 {
193 #define BUF &__stack.__buf
194 	struct {
195 		uint8_t padding_l;
196 		unsigned char __buf[8];
197 		uint8_t padding_r;
198 	} __stack;
199 	const size_t __bufsz __unused = sizeof(__stack.__buf);
200 	const size_t __len = 8 - 1;
201 	const size_t __idx __unused = __len - 1;
202 
203 	getcwd(__stack.__buf, __len);
204 #undef BUF
205 
206 }
207 
208 ATF_TC(getcwd_end);
209 ATF_TC_HEAD(getcwd_end, tc)
210 {
211 }
212 ATF_TC_BODY(getcwd_end, tc)
213 {
214 #define BUF &__stack.__buf
215 	struct {
216 		uint8_t padding_l;
217 		unsigned char __buf[8];
218 		uint8_t padding_r;
219 	} __stack;
220 	const size_t __bufsz __unused = sizeof(__stack.__buf);
221 	const size_t __len = 8;
222 	const size_t __idx __unused = __len - 1;
223 
224 	getcwd(__stack.__buf, __len);
225 #undef BUF
226 
227 }
228 
229 ATF_TC(getcwd_heap_before_end);
230 ATF_TC_HEAD(getcwd_heap_before_end, tc)
231 {
232 }
233 ATF_TC_BODY(getcwd_heap_before_end, tc)
234 {
235 #define BUF __stack.__buf
236 	struct {
237 		uint8_t padding_l;
238 		unsigned char * __buf;
239 		uint8_t padding_r;
240 	} __stack;
241 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (8);
242 	const size_t __len = 8 - 1;
243 	const size_t __idx __unused = __len - 1;
244 
245 	__stack.__buf = malloc(__bufsz);
246 
247 	getcwd(__stack.__buf, __len);
248 #undef BUF
249 
250 }
251 
252 ATF_TC(getcwd_heap_end);
253 ATF_TC_HEAD(getcwd_heap_end, tc)
254 {
255 }
256 ATF_TC_BODY(getcwd_heap_end, tc)
257 {
258 #define BUF __stack.__buf
259 	struct {
260 		uint8_t padding_l;
261 		unsigned char * __buf;
262 		uint8_t padding_r;
263 	} __stack;
264 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (8);
265 	const size_t __len = 8;
266 	const size_t __idx __unused = __len - 1;
267 
268 	__stack.__buf = malloc(__bufsz);
269 
270 	getcwd(__stack.__buf, __len);
271 #undef BUF
272 
273 }
274 
275 ATF_TC(getcwd_heap_after_end);
276 ATF_TC_HEAD(getcwd_heap_after_end, tc)
277 {
278 }
279 ATF_TC_BODY(getcwd_heap_after_end, tc)
280 {
281 #define BUF __stack.__buf
282 	struct {
283 		uint8_t padding_l;
284 		unsigned char * __buf;
285 		uint8_t padding_r;
286 	} __stack;
287 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (8);
288 	const size_t __len = 8 + 1;
289 	const size_t __idx __unused = __len - 1;
290 	pid_t __child;
291 	int __status;
292 
293 	__child = fork();
294 	ATF_REQUIRE(__child >= 0);
295 	if (__child > 0)
296 		goto monitor;
297 
298 	/* Child */
299 	disable_coredumps();
300 	__stack.__buf = malloc(__bufsz);
301 
302 	getcwd(__stack.__buf, __len);
303 	_exit(EX_SOFTWARE);	/* Should have aborted. */
304 
305 monitor:
306 	while (waitpid(__child, &__status, 0) != __child) {
307 		ATF_REQUIRE_EQ(EINTR, errno);
308 	}
309 
310 	if (!WIFSIGNALED(__status)) {
311 		switch (WEXITSTATUS(__status)) {
312 		case EX_SOFTWARE:
313 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
314 			break;
315 		case EX_OSERR:
316 			atf_tc_fail("setrlimit(2) failed");
317 			break;
318 		default:
319 			atf_tc_fail("child exited with status %d",
320 			    WEXITSTATUS(__status));
321 		}
322 	} else {
323 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
324 	}
325 #undef BUF
326 
327 }
328 
329 ATF_TC(getgrouplist_before_end);
330 ATF_TC_HEAD(getgrouplist_before_end, tc)
331 {
332 }
333 ATF_TC_BODY(getgrouplist_before_end, tc)
334 {
335 #define BUF &__stack.__buf
336 	struct {
337 		uint8_t padding_l;
338 		gid_t __buf[4];
339 		uint8_t padding_r;
340 	} __stack;
341 	const size_t __bufsz __unused = sizeof(__stack.__buf);
342 	const size_t __len = 4 - 1;
343 	const size_t __idx __unused = __len - 1;
344 	int intlen = (int)__len;
345 
346 	getgrouplist("root", 0, __stack.__buf, &intlen);
347 #undef BUF
348 
349 }
350 
351 ATF_TC(getgrouplist_end);
352 ATF_TC_HEAD(getgrouplist_end, tc)
353 {
354 }
355 ATF_TC_BODY(getgrouplist_end, tc)
356 {
357 #define BUF &__stack.__buf
358 	struct {
359 		uint8_t padding_l;
360 		gid_t __buf[4];
361 		uint8_t padding_r;
362 	} __stack;
363 	const size_t __bufsz __unused = sizeof(__stack.__buf);
364 	const size_t __len = 4;
365 	const size_t __idx __unused = __len - 1;
366 	int intlen = (int)__len;
367 
368 	getgrouplist("root", 0, __stack.__buf, &intlen);
369 #undef BUF
370 
371 }
372 
373 ATF_TC(getgrouplist_heap_before_end);
374 ATF_TC_HEAD(getgrouplist_heap_before_end, tc)
375 {
376 }
377 ATF_TC_BODY(getgrouplist_heap_before_end, tc)
378 {
379 #define BUF __stack.__buf
380 	struct {
381 		uint8_t padding_l;
382 		gid_t * __buf;
383 		uint8_t padding_r;
384 	} __stack;
385 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (4);
386 	const size_t __len = 4 - 1;
387 	const size_t __idx __unused = __len - 1;
388 	int intlen = (int)__len;
389 
390 	__stack.__buf = malloc(__bufsz);
391 
392 	getgrouplist("root", 0, __stack.__buf, &intlen);
393 #undef BUF
394 
395 }
396 
397 ATF_TC(getgrouplist_heap_end);
398 ATF_TC_HEAD(getgrouplist_heap_end, tc)
399 {
400 }
401 ATF_TC_BODY(getgrouplist_heap_end, tc)
402 {
403 #define BUF __stack.__buf
404 	struct {
405 		uint8_t padding_l;
406 		gid_t * __buf;
407 		uint8_t padding_r;
408 	} __stack;
409 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (4);
410 	const size_t __len = 4;
411 	const size_t __idx __unused = __len - 1;
412 	int intlen = (int)__len;
413 
414 	__stack.__buf = malloc(__bufsz);
415 
416 	getgrouplist("root", 0, __stack.__buf, &intlen);
417 #undef BUF
418 
419 }
420 
421 ATF_TC(getgrouplist_heap_after_end);
422 ATF_TC_HEAD(getgrouplist_heap_after_end, tc)
423 {
424 }
425 ATF_TC_BODY(getgrouplist_heap_after_end, tc)
426 {
427 #define BUF __stack.__buf
428 	struct {
429 		uint8_t padding_l;
430 		gid_t * __buf;
431 		uint8_t padding_r;
432 	} __stack;
433 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (4);
434 	const size_t __len = 4 + 1;
435 	const size_t __idx __unused = __len - 1;
436 	pid_t __child;
437 	int __status;
438 	int intlen = (int)__len;
439 
440 	__child = fork();
441 	ATF_REQUIRE(__child >= 0);
442 	if (__child > 0)
443 		goto monitor;
444 
445 	/* Child */
446 	disable_coredumps();
447 	__stack.__buf = malloc(__bufsz);
448 
449 	getgrouplist("root", 0, __stack.__buf, &intlen);
450 	_exit(EX_SOFTWARE);	/* Should have aborted. */
451 
452 monitor:
453 	while (waitpid(__child, &__status, 0) != __child) {
454 		ATF_REQUIRE_EQ(EINTR, errno);
455 	}
456 
457 	if (!WIFSIGNALED(__status)) {
458 		switch (WEXITSTATUS(__status)) {
459 		case EX_SOFTWARE:
460 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
461 			break;
462 		case EX_OSERR:
463 			atf_tc_fail("setrlimit(2) failed");
464 			break;
465 		default:
466 			atf_tc_fail("child exited with status %d",
467 			    WEXITSTATUS(__status));
468 		}
469 	} else {
470 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
471 	}
472 #undef BUF
473 
474 }
475 
476 ATF_TC(getgroups_before_end);
477 ATF_TC_HEAD(getgroups_before_end, tc)
478 {
479 }
480 ATF_TC_BODY(getgroups_before_end, tc)
481 {
482 #define BUF &__stack.__buf
483 	struct {
484 		uint8_t padding_l;
485 		gid_t __buf[4];
486 		uint8_t padding_r;
487 	} __stack;
488 	const size_t __bufsz __unused = sizeof(__stack.__buf);
489 	const size_t __len = 4 - 1;
490 	const size_t __idx __unused = __len - 1;
491 
492 	getgroups(__len, __stack.__buf);
493 #undef BUF
494 
495 }
496 
497 ATF_TC(getgroups_end);
498 ATF_TC_HEAD(getgroups_end, tc)
499 {
500 }
501 ATF_TC_BODY(getgroups_end, tc)
502 {
503 #define BUF &__stack.__buf
504 	struct {
505 		uint8_t padding_l;
506 		gid_t __buf[4];
507 		uint8_t padding_r;
508 	} __stack;
509 	const size_t __bufsz __unused = sizeof(__stack.__buf);
510 	const size_t __len = 4;
511 	const size_t __idx __unused = __len - 1;
512 
513 	getgroups(__len, __stack.__buf);
514 #undef BUF
515 
516 }
517 
518 ATF_TC(getgroups_heap_before_end);
519 ATF_TC_HEAD(getgroups_heap_before_end, tc)
520 {
521 }
522 ATF_TC_BODY(getgroups_heap_before_end, tc)
523 {
524 #define BUF __stack.__buf
525 	struct {
526 		uint8_t padding_l;
527 		gid_t * __buf;
528 		uint8_t padding_r;
529 	} __stack;
530 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (4);
531 	const size_t __len = 4 - 1;
532 	const size_t __idx __unused = __len - 1;
533 
534 	__stack.__buf = malloc(__bufsz);
535 
536 	getgroups(__len, __stack.__buf);
537 #undef BUF
538 
539 }
540 
541 ATF_TC(getgroups_heap_end);
542 ATF_TC_HEAD(getgroups_heap_end, tc)
543 {
544 }
545 ATF_TC_BODY(getgroups_heap_end, tc)
546 {
547 #define BUF __stack.__buf
548 	struct {
549 		uint8_t padding_l;
550 		gid_t * __buf;
551 		uint8_t padding_r;
552 	} __stack;
553 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (4);
554 	const size_t __len = 4;
555 	const size_t __idx __unused = __len - 1;
556 
557 	__stack.__buf = malloc(__bufsz);
558 
559 	getgroups(__len, __stack.__buf);
560 #undef BUF
561 
562 }
563 
564 ATF_TC(getgroups_heap_after_end);
565 ATF_TC_HEAD(getgroups_heap_after_end, tc)
566 {
567 }
568 ATF_TC_BODY(getgroups_heap_after_end, tc)
569 {
570 #define BUF __stack.__buf
571 	struct {
572 		uint8_t padding_l;
573 		gid_t * __buf;
574 		uint8_t padding_r;
575 	} __stack;
576 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (4);
577 	const size_t __len = 4 + 1;
578 	const size_t __idx __unused = __len - 1;
579 	pid_t __child;
580 	int __status;
581 
582 	__child = fork();
583 	ATF_REQUIRE(__child >= 0);
584 	if (__child > 0)
585 		goto monitor;
586 
587 	/* Child */
588 	disable_coredumps();
589 	__stack.__buf = malloc(__bufsz);
590 
591 	getgroups(__len, __stack.__buf);
592 	_exit(EX_SOFTWARE);	/* Should have aborted. */
593 
594 monitor:
595 	while (waitpid(__child, &__status, 0) != __child) {
596 		ATF_REQUIRE_EQ(EINTR, errno);
597 	}
598 
599 	if (!WIFSIGNALED(__status)) {
600 		switch (WEXITSTATUS(__status)) {
601 		case EX_SOFTWARE:
602 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
603 			break;
604 		case EX_OSERR:
605 			atf_tc_fail("setrlimit(2) failed");
606 			break;
607 		default:
608 			atf_tc_fail("child exited with status %d",
609 			    WEXITSTATUS(__status));
610 		}
611 	} else {
612 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
613 	}
614 #undef BUF
615 
616 }
617 
618 ATF_TC(getloginclass_before_end);
619 ATF_TC_HEAD(getloginclass_before_end, tc)
620 {
621 }
622 ATF_TC_BODY(getloginclass_before_end, tc)
623 {
624 #define BUF &__stack.__buf
625 	struct {
626 		uint8_t padding_l;
627 		unsigned char __buf[42];
628 		uint8_t padding_r;
629 	} __stack;
630 	const size_t __bufsz __unused = sizeof(__stack.__buf);
631 	const size_t __len = 42 - 1;
632 	const size_t __idx __unused = __len - 1;
633 
634 	getloginclass(__stack.__buf, __len);
635 #undef BUF
636 
637 }
638 
639 ATF_TC(getloginclass_end);
640 ATF_TC_HEAD(getloginclass_end, tc)
641 {
642 }
643 ATF_TC_BODY(getloginclass_end, tc)
644 {
645 #define BUF &__stack.__buf
646 	struct {
647 		uint8_t padding_l;
648 		unsigned char __buf[42];
649 		uint8_t padding_r;
650 	} __stack;
651 	const size_t __bufsz __unused = sizeof(__stack.__buf);
652 	const size_t __len = 42;
653 	const size_t __idx __unused = __len - 1;
654 
655 	getloginclass(__stack.__buf, __len);
656 #undef BUF
657 
658 }
659 
660 ATF_TC(getloginclass_heap_before_end);
661 ATF_TC_HEAD(getloginclass_heap_before_end, tc)
662 {
663 }
664 ATF_TC_BODY(getloginclass_heap_before_end, tc)
665 {
666 #define BUF __stack.__buf
667 	struct {
668 		uint8_t padding_l;
669 		unsigned char * __buf;
670 		uint8_t padding_r;
671 	} __stack;
672 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
673 	const size_t __len = 42 - 1;
674 	const size_t __idx __unused = __len - 1;
675 
676 	__stack.__buf = malloc(__bufsz);
677 
678 	getloginclass(__stack.__buf, __len);
679 #undef BUF
680 
681 }
682 
683 ATF_TC(getloginclass_heap_end);
684 ATF_TC_HEAD(getloginclass_heap_end, tc)
685 {
686 }
687 ATF_TC_BODY(getloginclass_heap_end, tc)
688 {
689 #define BUF __stack.__buf
690 	struct {
691 		uint8_t padding_l;
692 		unsigned char * __buf;
693 		uint8_t padding_r;
694 	} __stack;
695 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
696 	const size_t __len = 42;
697 	const size_t __idx __unused = __len - 1;
698 
699 	__stack.__buf = malloc(__bufsz);
700 
701 	getloginclass(__stack.__buf, __len);
702 #undef BUF
703 
704 }
705 
706 ATF_TC(getloginclass_heap_after_end);
707 ATF_TC_HEAD(getloginclass_heap_after_end, tc)
708 {
709 }
710 ATF_TC_BODY(getloginclass_heap_after_end, tc)
711 {
712 #define BUF __stack.__buf
713 	struct {
714 		uint8_t padding_l;
715 		unsigned char * __buf;
716 		uint8_t padding_r;
717 	} __stack;
718 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
719 	const size_t __len = 42 + 1;
720 	const size_t __idx __unused = __len - 1;
721 	pid_t __child;
722 	int __status;
723 
724 	__child = fork();
725 	ATF_REQUIRE(__child >= 0);
726 	if (__child > 0)
727 		goto monitor;
728 
729 	/* Child */
730 	disable_coredumps();
731 	__stack.__buf = malloc(__bufsz);
732 
733 	getloginclass(__stack.__buf, __len);
734 	_exit(EX_SOFTWARE);	/* Should have aborted. */
735 
736 monitor:
737 	while (waitpid(__child, &__status, 0) != __child) {
738 		ATF_REQUIRE_EQ(EINTR, errno);
739 	}
740 
741 	if (!WIFSIGNALED(__status)) {
742 		switch (WEXITSTATUS(__status)) {
743 		case EX_SOFTWARE:
744 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
745 			break;
746 		case EX_OSERR:
747 			atf_tc_fail("setrlimit(2) failed");
748 			break;
749 		default:
750 			atf_tc_fail("child exited with status %d",
751 			    WEXITSTATUS(__status));
752 		}
753 	} else {
754 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
755 	}
756 #undef BUF
757 
758 }
759 
760 ATF_TC(pread_before_end);
761 ATF_TC_HEAD(pread_before_end, tc)
762 {
763 }
764 ATF_TC_BODY(pread_before_end, tc)
765 {
766 #define BUF &__stack.__buf
767 	struct {
768 		uint8_t padding_l;
769 		unsigned char __buf[41];
770 		uint8_t padding_r;
771 	} __stack;
772 	const size_t __bufsz __unused = sizeof(__stack.__buf);
773 	const size_t __len = 41 - 1;
774 	const size_t __idx __unused = __len - 1;
775 	int fd;
776 
777 	fd = new_tmpfile();	/* Cannot fail */
778 
779 	pread(fd, __stack.__buf, __len, 0);
780 #undef BUF
781 
782 }
783 
784 ATF_TC(pread_end);
785 ATF_TC_HEAD(pread_end, tc)
786 {
787 }
788 ATF_TC_BODY(pread_end, tc)
789 {
790 #define BUF &__stack.__buf
791 	struct {
792 		uint8_t padding_l;
793 		unsigned char __buf[41];
794 		uint8_t padding_r;
795 	} __stack;
796 	const size_t __bufsz __unused = sizeof(__stack.__buf);
797 	const size_t __len = 41;
798 	const size_t __idx __unused = __len - 1;
799 	int fd;
800 
801 	fd = new_tmpfile();	/* Cannot fail */
802 
803 	pread(fd, __stack.__buf, __len, 0);
804 #undef BUF
805 
806 }
807 
808 ATF_TC(pread_heap_before_end);
809 ATF_TC_HEAD(pread_heap_before_end, tc)
810 {
811 }
812 ATF_TC_BODY(pread_heap_before_end, tc)
813 {
814 #define BUF __stack.__buf
815 	struct {
816 		uint8_t padding_l;
817 		unsigned char * __buf;
818 		uint8_t padding_r;
819 	} __stack;
820 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (41);
821 	const size_t __len = 41 - 1;
822 	const size_t __idx __unused = __len - 1;
823 	int fd;
824 
825 	__stack.__buf = malloc(__bufsz);
826 	fd = new_tmpfile();	/* Cannot fail */
827 
828 	pread(fd, __stack.__buf, __len, 0);
829 #undef BUF
830 
831 }
832 
833 ATF_TC(pread_heap_end);
834 ATF_TC_HEAD(pread_heap_end, tc)
835 {
836 }
837 ATF_TC_BODY(pread_heap_end, tc)
838 {
839 #define BUF __stack.__buf
840 	struct {
841 		uint8_t padding_l;
842 		unsigned char * __buf;
843 		uint8_t padding_r;
844 	} __stack;
845 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (41);
846 	const size_t __len = 41;
847 	const size_t __idx __unused = __len - 1;
848 	int fd;
849 
850 	__stack.__buf = malloc(__bufsz);
851 	fd = new_tmpfile();	/* Cannot fail */
852 
853 	pread(fd, __stack.__buf, __len, 0);
854 #undef BUF
855 
856 }
857 
858 ATF_TC(pread_heap_after_end);
859 ATF_TC_HEAD(pread_heap_after_end, tc)
860 {
861 }
862 ATF_TC_BODY(pread_heap_after_end, tc)
863 {
864 #define BUF __stack.__buf
865 	struct {
866 		uint8_t padding_l;
867 		unsigned char * __buf;
868 		uint8_t padding_r;
869 	} __stack;
870 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (41);
871 	const size_t __len = 41 + 1;
872 	const size_t __idx __unused = __len - 1;
873 	pid_t __child;
874 	int __status;
875 	int fd;
876 
877 	__child = fork();
878 	ATF_REQUIRE(__child >= 0);
879 	if (__child > 0)
880 		goto monitor;
881 
882 	/* Child */
883 	disable_coredumps();
884 	__stack.__buf = malloc(__bufsz);
885 	fd = new_tmpfile();	/* Cannot fail */
886 
887 	pread(fd, __stack.__buf, __len, 0);
888 	_exit(EX_SOFTWARE);	/* Should have aborted. */
889 
890 monitor:
891 	while (waitpid(__child, &__status, 0) != __child) {
892 		ATF_REQUIRE_EQ(EINTR, errno);
893 	}
894 
895 	if (!WIFSIGNALED(__status)) {
896 		switch (WEXITSTATUS(__status)) {
897 		case EX_SOFTWARE:
898 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
899 			break;
900 		case EX_OSERR:
901 			atf_tc_fail("setrlimit(2) failed");
902 			break;
903 		default:
904 			atf_tc_fail("child exited with status %d",
905 			    WEXITSTATUS(__status));
906 		}
907 	} else {
908 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
909 	}
910 #undef BUF
911 
912 }
913 
914 ATF_TC(read_before_end);
915 ATF_TC_HEAD(read_before_end, tc)
916 {
917 }
918 ATF_TC_BODY(read_before_end, tc)
919 {
920 #define BUF &__stack.__buf
921 	struct {
922 		uint8_t padding_l;
923 		unsigned char __buf[41];
924 		uint8_t padding_r;
925 	} __stack;
926 	const size_t __bufsz __unused = sizeof(__stack.__buf);
927 	const size_t __len = 41 - 1;
928 	const size_t __idx __unused = __len - 1;
929 	int fd;
930 
931 	fd = new_tmpfile();	/* Cannot fail */
932 
933 	read(fd, __stack.__buf, __len);
934 #undef BUF
935 
936 }
937 
938 ATF_TC(read_end);
939 ATF_TC_HEAD(read_end, tc)
940 {
941 }
942 ATF_TC_BODY(read_end, tc)
943 {
944 #define BUF &__stack.__buf
945 	struct {
946 		uint8_t padding_l;
947 		unsigned char __buf[41];
948 		uint8_t padding_r;
949 	} __stack;
950 	const size_t __bufsz __unused = sizeof(__stack.__buf);
951 	const size_t __len = 41;
952 	const size_t __idx __unused = __len - 1;
953 	int fd;
954 
955 	fd = new_tmpfile();	/* Cannot fail */
956 
957 	read(fd, __stack.__buf, __len);
958 #undef BUF
959 
960 }
961 
962 ATF_TC(read_heap_before_end);
963 ATF_TC_HEAD(read_heap_before_end, tc)
964 {
965 }
966 ATF_TC_BODY(read_heap_before_end, tc)
967 {
968 #define BUF __stack.__buf
969 	struct {
970 		uint8_t padding_l;
971 		unsigned char * __buf;
972 		uint8_t padding_r;
973 	} __stack;
974 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (41);
975 	const size_t __len = 41 - 1;
976 	const size_t __idx __unused = __len - 1;
977 	int fd;
978 
979 	__stack.__buf = malloc(__bufsz);
980 	fd = new_tmpfile();	/* Cannot fail */
981 
982 	read(fd, __stack.__buf, __len);
983 #undef BUF
984 
985 }
986 
987 ATF_TC(read_heap_end);
988 ATF_TC_HEAD(read_heap_end, tc)
989 {
990 }
991 ATF_TC_BODY(read_heap_end, tc)
992 {
993 #define BUF __stack.__buf
994 	struct {
995 		uint8_t padding_l;
996 		unsigned char * __buf;
997 		uint8_t padding_r;
998 	} __stack;
999 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (41);
1000 	const size_t __len = 41;
1001 	const size_t __idx __unused = __len - 1;
1002 	int fd;
1003 
1004 	__stack.__buf = malloc(__bufsz);
1005 	fd = new_tmpfile();	/* Cannot fail */
1006 
1007 	read(fd, __stack.__buf, __len);
1008 #undef BUF
1009 
1010 }
1011 
1012 ATF_TC(read_heap_after_end);
1013 ATF_TC_HEAD(read_heap_after_end, tc)
1014 {
1015 }
1016 ATF_TC_BODY(read_heap_after_end, tc)
1017 {
1018 #define BUF __stack.__buf
1019 	struct {
1020 		uint8_t padding_l;
1021 		unsigned char * __buf;
1022 		uint8_t padding_r;
1023 	} __stack;
1024 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (41);
1025 	const size_t __len = 41 + 1;
1026 	const size_t __idx __unused = __len - 1;
1027 	pid_t __child;
1028 	int __status;
1029 	int fd;
1030 
1031 	__child = fork();
1032 	ATF_REQUIRE(__child >= 0);
1033 	if (__child > 0)
1034 		goto monitor;
1035 
1036 	/* Child */
1037 	disable_coredumps();
1038 	__stack.__buf = malloc(__bufsz);
1039 	fd = new_tmpfile();	/* Cannot fail */
1040 
1041 	read(fd, __stack.__buf, __len);
1042 	_exit(EX_SOFTWARE);	/* Should have aborted. */
1043 
1044 monitor:
1045 	while (waitpid(__child, &__status, 0) != __child) {
1046 		ATF_REQUIRE_EQ(EINTR, errno);
1047 	}
1048 
1049 	if (!WIFSIGNALED(__status)) {
1050 		switch (WEXITSTATUS(__status)) {
1051 		case EX_SOFTWARE:
1052 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
1053 			break;
1054 		case EX_OSERR:
1055 			atf_tc_fail("setrlimit(2) failed");
1056 			break;
1057 		default:
1058 			atf_tc_fail("child exited with status %d",
1059 			    WEXITSTATUS(__status));
1060 		}
1061 	} else {
1062 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
1063 	}
1064 #undef BUF
1065 
1066 }
1067 
1068 ATF_TC(readlink_before_end);
1069 ATF_TC_HEAD(readlink_before_end, tc)
1070 {
1071 }
1072 ATF_TC_BODY(readlink_before_end, tc)
1073 {
1074 #define BUF &__stack.__buf
1075 	struct {
1076 		uint8_t padding_l;
1077 		unsigned char __buf[42];
1078 		uint8_t padding_r;
1079 	} __stack;
1080 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1081 	const size_t __len = 42 - 1;
1082 	const size_t __idx __unused = __len - 1;
1083 	const char *path;
1084 
1085 	path = new_symlink(__len);		/* Cannot fail */
1086 
1087 	readlink(path, __stack.__buf, __len);
1088 #undef BUF
1089 
1090 }
1091 
1092 ATF_TC(readlink_end);
1093 ATF_TC_HEAD(readlink_end, tc)
1094 {
1095 }
1096 ATF_TC_BODY(readlink_end, tc)
1097 {
1098 #define BUF &__stack.__buf
1099 	struct {
1100 		uint8_t padding_l;
1101 		unsigned char __buf[42];
1102 		uint8_t padding_r;
1103 	} __stack;
1104 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1105 	const size_t __len = 42;
1106 	const size_t __idx __unused = __len - 1;
1107 	const char *path;
1108 
1109 	path = new_symlink(__len);		/* Cannot fail */
1110 
1111 	readlink(path, __stack.__buf, __len);
1112 #undef BUF
1113 
1114 }
1115 
1116 ATF_TC(readlink_heap_before_end);
1117 ATF_TC_HEAD(readlink_heap_before_end, tc)
1118 {
1119 }
1120 ATF_TC_BODY(readlink_heap_before_end, tc)
1121 {
1122 #define BUF __stack.__buf
1123 	struct {
1124 		uint8_t padding_l;
1125 		unsigned char * __buf;
1126 		uint8_t padding_r;
1127 	} __stack;
1128 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
1129 	const size_t __len = 42 - 1;
1130 	const size_t __idx __unused = __len - 1;
1131 	const char *path;
1132 
1133 	__stack.__buf = malloc(__bufsz);
1134 	path = new_symlink(__len);		/* Cannot fail */
1135 
1136 	readlink(path, __stack.__buf, __len);
1137 #undef BUF
1138 
1139 }
1140 
1141 ATF_TC(readlink_heap_end);
1142 ATF_TC_HEAD(readlink_heap_end, tc)
1143 {
1144 }
1145 ATF_TC_BODY(readlink_heap_end, tc)
1146 {
1147 #define BUF __stack.__buf
1148 	struct {
1149 		uint8_t padding_l;
1150 		unsigned char * __buf;
1151 		uint8_t padding_r;
1152 	} __stack;
1153 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
1154 	const size_t __len = 42;
1155 	const size_t __idx __unused = __len - 1;
1156 	const char *path;
1157 
1158 	__stack.__buf = malloc(__bufsz);
1159 	path = new_symlink(__len);		/* Cannot fail */
1160 
1161 	readlink(path, __stack.__buf, __len);
1162 #undef BUF
1163 
1164 }
1165 
1166 ATF_TC(readlink_heap_after_end);
1167 ATF_TC_HEAD(readlink_heap_after_end, tc)
1168 {
1169 }
1170 ATF_TC_BODY(readlink_heap_after_end, tc)
1171 {
1172 #define BUF __stack.__buf
1173 	struct {
1174 		uint8_t padding_l;
1175 		unsigned char * __buf;
1176 		uint8_t padding_r;
1177 	} __stack;
1178 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
1179 	const size_t __len = 42 + 1;
1180 	const size_t __idx __unused = __len - 1;
1181 	pid_t __child;
1182 	int __status;
1183 	const char *path;
1184 
1185 	__child = fork();
1186 	ATF_REQUIRE(__child >= 0);
1187 	if (__child > 0)
1188 		goto monitor;
1189 
1190 	/* Child */
1191 	disable_coredumps();
1192 	__stack.__buf = malloc(__bufsz);
1193 	path = new_symlink(__len);		/* Cannot fail */
1194 
1195 	readlink(path, __stack.__buf, __len);
1196 	_exit(EX_SOFTWARE);	/* Should have aborted. */
1197 
1198 monitor:
1199 	while (waitpid(__child, &__status, 0) != __child) {
1200 		ATF_REQUIRE_EQ(EINTR, errno);
1201 	}
1202 
1203 	if (!WIFSIGNALED(__status)) {
1204 		switch (WEXITSTATUS(__status)) {
1205 		case EX_SOFTWARE:
1206 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
1207 			break;
1208 		case EX_OSERR:
1209 			atf_tc_fail("setrlimit(2) failed");
1210 			break;
1211 		default:
1212 			atf_tc_fail("child exited with status %d",
1213 			    WEXITSTATUS(__status));
1214 		}
1215 	} else {
1216 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
1217 	}
1218 #undef BUF
1219 
1220 }
1221 
1222 ATF_TC(readlinkat_before_end);
1223 ATF_TC_HEAD(readlinkat_before_end, tc)
1224 {
1225 }
1226 ATF_TC_BODY(readlinkat_before_end, tc)
1227 {
1228 #define BUF &__stack.__buf
1229 	struct {
1230 		uint8_t padding_l;
1231 		unsigned char __buf[42];
1232 		uint8_t padding_r;
1233 	} __stack;
1234 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1235 	const size_t __len = 42 - 1;
1236 	const size_t __idx __unused = __len - 1;
1237 	const char *path;
1238 
1239 	path = new_symlink(__len);		/* Cannot fail */
1240 
1241 	readlinkat(AT_FDCWD, path, __stack.__buf, __len);
1242 #undef BUF
1243 
1244 }
1245 
1246 ATF_TC(readlinkat_end);
1247 ATF_TC_HEAD(readlinkat_end, tc)
1248 {
1249 }
1250 ATF_TC_BODY(readlinkat_end, tc)
1251 {
1252 #define BUF &__stack.__buf
1253 	struct {
1254 		uint8_t padding_l;
1255 		unsigned char __buf[42];
1256 		uint8_t padding_r;
1257 	} __stack;
1258 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1259 	const size_t __len = 42;
1260 	const size_t __idx __unused = __len - 1;
1261 	const char *path;
1262 
1263 	path = new_symlink(__len);		/* Cannot fail */
1264 
1265 	readlinkat(AT_FDCWD, path, __stack.__buf, __len);
1266 #undef BUF
1267 
1268 }
1269 
1270 ATF_TC(readlinkat_heap_before_end);
1271 ATF_TC_HEAD(readlinkat_heap_before_end, tc)
1272 {
1273 }
1274 ATF_TC_BODY(readlinkat_heap_before_end, tc)
1275 {
1276 #define BUF __stack.__buf
1277 	struct {
1278 		uint8_t padding_l;
1279 		unsigned char * __buf;
1280 		uint8_t padding_r;
1281 	} __stack;
1282 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
1283 	const size_t __len = 42 - 1;
1284 	const size_t __idx __unused = __len - 1;
1285 	const char *path;
1286 
1287 	__stack.__buf = malloc(__bufsz);
1288 	path = new_symlink(__len);		/* Cannot fail */
1289 
1290 	readlinkat(AT_FDCWD, path, __stack.__buf, __len);
1291 #undef BUF
1292 
1293 }
1294 
1295 ATF_TC(readlinkat_heap_end);
1296 ATF_TC_HEAD(readlinkat_heap_end, tc)
1297 {
1298 }
1299 ATF_TC_BODY(readlinkat_heap_end, tc)
1300 {
1301 #define BUF __stack.__buf
1302 	struct {
1303 		uint8_t padding_l;
1304 		unsigned char * __buf;
1305 		uint8_t padding_r;
1306 	} __stack;
1307 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
1308 	const size_t __len = 42;
1309 	const size_t __idx __unused = __len - 1;
1310 	const char *path;
1311 
1312 	__stack.__buf = malloc(__bufsz);
1313 	path = new_symlink(__len);		/* Cannot fail */
1314 
1315 	readlinkat(AT_FDCWD, path, __stack.__buf, __len);
1316 #undef BUF
1317 
1318 }
1319 
1320 ATF_TC(readlinkat_heap_after_end);
1321 ATF_TC_HEAD(readlinkat_heap_after_end, tc)
1322 {
1323 }
1324 ATF_TC_BODY(readlinkat_heap_after_end, tc)
1325 {
1326 #define BUF __stack.__buf
1327 	struct {
1328 		uint8_t padding_l;
1329 		unsigned char * __buf;
1330 		uint8_t padding_r;
1331 	} __stack;
1332 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
1333 	const size_t __len = 42 + 1;
1334 	const size_t __idx __unused = __len - 1;
1335 	pid_t __child;
1336 	int __status;
1337 	const char *path;
1338 
1339 	__child = fork();
1340 	ATF_REQUIRE(__child >= 0);
1341 	if (__child > 0)
1342 		goto monitor;
1343 
1344 	/* Child */
1345 	disable_coredumps();
1346 	__stack.__buf = malloc(__bufsz);
1347 	path = new_symlink(__len);		/* Cannot fail */
1348 
1349 	readlinkat(AT_FDCWD, path, __stack.__buf, __len);
1350 	_exit(EX_SOFTWARE);	/* Should have aborted. */
1351 
1352 monitor:
1353 	while (waitpid(__child, &__status, 0) != __child) {
1354 		ATF_REQUIRE_EQ(EINTR, errno);
1355 	}
1356 
1357 	if (!WIFSIGNALED(__status)) {
1358 		switch (WEXITSTATUS(__status)) {
1359 		case EX_SOFTWARE:
1360 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
1361 			break;
1362 		case EX_OSERR:
1363 			atf_tc_fail("setrlimit(2) failed");
1364 			break;
1365 		default:
1366 			atf_tc_fail("child exited with status %d",
1367 			    WEXITSTATUS(__status));
1368 		}
1369 	} else {
1370 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
1371 	}
1372 #undef BUF
1373 
1374 }
1375 
1376 ATF_TC(getdomainname_before_end);
1377 ATF_TC_HEAD(getdomainname_before_end, tc)
1378 {
1379 	atf_tc_set_md_var(tc, "require.user", "root");
1380 }
1381 ATF_TC_BODY(getdomainname_before_end, tc)
1382 {
1383 #define BUF &__stack.__buf
1384 	struct {
1385 		uint8_t padding_l;
1386 		unsigned char __buf[12];
1387 		uint8_t padding_r;
1388 	} __stack;
1389 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1390 	const size_t __len = 12 - 1;
1391 	const size_t __idx __unused = __len - 1;
1392 
1393 	dhost_jail();
1394 	getdomainname(__stack.__buf, __len);
1395 #undef BUF
1396 
1397 }
1398 
1399 ATF_TC(getdomainname_end);
1400 ATF_TC_HEAD(getdomainname_end, tc)
1401 {
1402 	atf_tc_set_md_var(tc, "require.user", "root");
1403 }
1404 ATF_TC_BODY(getdomainname_end, tc)
1405 {
1406 #define BUF &__stack.__buf
1407 	struct {
1408 		uint8_t padding_l;
1409 		unsigned char __buf[12];
1410 		uint8_t padding_r;
1411 	} __stack;
1412 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1413 	const size_t __len = 12;
1414 	const size_t __idx __unused = __len - 1;
1415 
1416 	dhost_jail();
1417 	getdomainname(__stack.__buf, __len);
1418 #undef BUF
1419 
1420 }
1421 
1422 ATF_TC(getdomainname_heap_before_end);
1423 ATF_TC_HEAD(getdomainname_heap_before_end, tc)
1424 {
1425 	atf_tc_set_md_var(tc, "require.user", "root");
1426 }
1427 ATF_TC_BODY(getdomainname_heap_before_end, tc)
1428 {
1429 #define BUF __stack.__buf
1430 	struct {
1431 		uint8_t padding_l;
1432 		unsigned char * __buf;
1433 		uint8_t padding_r;
1434 	} __stack;
1435 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (12);
1436 	const size_t __len = 12 - 1;
1437 	const size_t __idx __unused = __len - 1;
1438 
1439 	dhost_jail();
1440 	__stack.__buf = malloc(__bufsz);
1441 
1442 	getdomainname(__stack.__buf, __len);
1443 #undef BUF
1444 
1445 }
1446 
1447 ATF_TC(getdomainname_heap_end);
1448 ATF_TC_HEAD(getdomainname_heap_end, tc)
1449 {
1450 	atf_tc_set_md_var(tc, "require.user", "root");
1451 }
1452 ATF_TC_BODY(getdomainname_heap_end, tc)
1453 {
1454 #define BUF __stack.__buf
1455 	struct {
1456 		uint8_t padding_l;
1457 		unsigned char * __buf;
1458 		uint8_t padding_r;
1459 	} __stack;
1460 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (12);
1461 	const size_t __len = 12;
1462 	const size_t __idx __unused = __len - 1;
1463 
1464 	dhost_jail();
1465 	__stack.__buf = malloc(__bufsz);
1466 
1467 	getdomainname(__stack.__buf, __len);
1468 #undef BUF
1469 
1470 }
1471 
1472 ATF_TC(getdomainname_heap_after_end);
1473 ATF_TC_HEAD(getdomainname_heap_after_end, tc)
1474 {
1475 	atf_tc_set_md_var(tc, "require.user", "root");
1476 }
1477 ATF_TC_BODY(getdomainname_heap_after_end, tc)
1478 {
1479 #define BUF __stack.__buf
1480 	struct {
1481 		uint8_t padding_l;
1482 		unsigned char * __buf;
1483 		uint8_t padding_r;
1484 	} __stack;
1485 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (12);
1486 	const size_t __len = 12 + 1;
1487 	const size_t __idx __unused = __len - 1;
1488 	pid_t __child;
1489 	int __status;
1490 
1491 	dhost_jail();
1492 	__child = fork();
1493 	ATF_REQUIRE(__child >= 0);
1494 	if (__child > 0)
1495 		goto monitor;
1496 
1497 	/* Child */
1498 	disable_coredumps();
1499 	__stack.__buf = malloc(__bufsz);
1500 
1501 	getdomainname(__stack.__buf, __len);
1502 	_exit(EX_SOFTWARE);	/* Should have aborted. */
1503 
1504 monitor:
1505 	while (waitpid(__child, &__status, 0) != __child) {
1506 		ATF_REQUIRE_EQ(EINTR, errno);
1507 	}
1508 
1509 	if (!WIFSIGNALED(__status)) {
1510 		switch (WEXITSTATUS(__status)) {
1511 		case EX_SOFTWARE:
1512 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
1513 			break;
1514 		case EX_OSERR:
1515 			atf_tc_fail("setrlimit(2) failed");
1516 			break;
1517 		default:
1518 			atf_tc_fail("child exited with status %d",
1519 			    WEXITSTATUS(__status));
1520 		}
1521 	} else {
1522 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
1523 	}
1524 #undef BUF
1525 
1526 }
1527 
1528 ATF_TC(getentropy_before_end);
1529 ATF_TC_HEAD(getentropy_before_end, tc)
1530 {
1531 }
1532 ATF_TC_BODY(getentropy_before_end, tc)
1533 {
1534 #define BUF &__stack.__buf
1535 	struct {
1536 		uint8_t padding_l;
1537 		unsigned char __buf[42];
1538 		uint8_t padding_r;
1539 	} __stack;
1540 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1541 	const size_t __len = 42 - 1;
1542 	const size_t __idx __unused = __len - 1;
1543 
1544 	getentropy(__stack.__buf, __len);
1545 #undef BUF
1546 
1547 }
1548 
1549 ATF_TC(getentropy_end);
1550 ATF_TC_HEAD(getentropy_end, tc)
1551 {
1552 }
1553 ATF_TC_BODY(getentropy_end, tc)
1554 {
1555 #define BUF &__stack.__buf
1556 	struct {
1557 		uint8_t padding_l;
1558 		unsigned char __buf[42];
1559 		uint8_t padding_r;
1560 	} __stack;
1561 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1562 	const size_t __len = 42;
1563 	const size_t __idx __unused = __len - 1;
1564 
1565 	getentropy(__stack.__buf, __len);
1566 #undef BUF
1567 
1568 }
1569 
1570 ATF_TC(getentropy_heap_before_end);
1571 ATF_TC_HEAD(getentropy_heap_before_end, tc)
1572 {
1573 }
1574 ATF_TC_BODY(getentropy_heap_before_end, tc)
1575 {
1576 #define BUF __stack.__buf
1577 	struct {
1578 		uint8_t padding_l;
1579 		unsigned char * __buf;
1580 		uint8_t padding_r;
1581 	} __stack;
1582 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
1583 	const size_t __len = 42 - 1;
1584 	const size_t __idx __unused = __len - 1;
1585 
1586 	__stack.__buf = malloc(__bufsz);
1587 
1588 	getentropy(__stack.__buf, __len);
1589 #undef BUF
1590 
1591 }
1592 
1593 ATF_TC(getentropy_heap_end);
1594 ATF_TC_HEAD(getentropy_heap_end, tc)
1595 {
1596 }
1597 ATF_TC_BODY(getentropy_heap_end, tc)
1598 {
1599 #define BUF __stack.__buf
1600 	struct {
1601 		uint8_t padding_l;
1602 		unsigned char * __buf;
1603 		uint8_t padding_r;
1604 	} __stack;
1605 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
1606 	const size_t __len = 42;
1607 	const size_t __idx __unused = __len - 1;
1608 
1609 	__stack.__buf = malloc(__bufsz);
1610 
1611 	getentropy(__stack.__buf, __len);
1612 #undef BUF
1613 
1614 }
1615 
1616 ATF_TC(getentropy_heap_after_end);
1617 ATF_TC_HEAD(getentropy_heap_after_end, tc)
1618 {
1619 }
1620 ATF_TC_BODY(getentropy_heap_after_end, tc)
1621 {
1622 #define BUF __stack.__buf
1623 	struct {
1624 		uint8_t padding_l;
1625 		unsigned char * __buf;
1626 		uint8_t padding_r;
1627 	} __stack;
1628 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
1629 	const size_t __len = 42 + 1;
1630 	const size_t __idx __unused = __len - 1;
1631 	pid_t __child;
1632 	int __status;
1633 
1634 	__child = fork();
1635 	ATF_REQUIRE(__child >= 0);
1636 	if (__child > 0)
1637 		goto monitor;
1638 
1639 	/* Child */
1640 	disable_coredumps();
1641 	__stack.__buf = malloc(__bufsz);
1642 
1643 	getentropy(__stack.__buf, __len);
1644 	_exit(EX_SOFTWARE);	/* Should have aborted. */
1645 
1646 monitor:
1647 	while (waitpid(__child, &__status, 0) != __child) {
1648 		ATF_REQUIRE_EQ(EINTR, errno);
1649 	}
1650 
1651 	if (!WIFSIGNALED(__status)) {
1652 		switch (WEXITSTATUS(__status)) {
1653 		case EX_SOFTWARE:
1654 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
1655 			break;
1656 		case EX_OSERR:
1657 			atf_tc_fail("setrlimit(2) failed");
1658 			break;
1659 		default:
1660 			atf_tc_fail("child exited with status %d",
1661 			    WEXITSTATUS(__status));
1662 		}
1663 	} else {
1664 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
1665 	}
1666 #undef BUF
1667 
1668 }
1669 
1670 ATF_TC(gethostname_before_end);
1671 ATF_TC_HEAD(gethostname_before_end, tc)
1672 {
1673 	atf_tc_set_md_var(tc, "require.user", "root");
1674 }
1675 ATF_TC_BODY(gethostname_before_end, tc)
1676 {
1677 #define BUF &__stack.__buf
1678 	struct {
1679 		uint8_t padding_l;
1680 		unsigned char __buf[17];
1681 		uint8_t padding_r;
1682 	} __stack;
1683 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1684 	const size_t __len = 17 - 1;
1685 	const size_t __idx __unused = __len - 1;
1686 
1687 	dhost_jail();
1688 	gethostname(__stack.__buf, __len);
1689 #undef BUF
1690 
1691 }
1692 
1693 ATF_TC(gethostname_end);
1694 ATF_TC_HEAD(gethostname_end, tc)
1695 {
1696 	atf_tc_set_md_var(tc, "require.user", "root");
1697 }
1698 ATF_TC_BODY(gethostname_end, tc)
1699 {
1700 #define BUF &__stack.__buf
1701 	struct {
1702 		uint8_t padding_l;
1703 		unsigned char __buf[17];
1704 		uint8_t padding_r;
1705 	} __stack;
1706 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1707 	const size_t __len = 17;
1708 	const size_t __idx __unused = __len - 1;
1709 
1710 	dhost_jail();
1711 	gethostname(__stack.__buf, __len);
1712 #undef BUF
1713 
1714 }
1715 
1716 ATF_TC(gethostname_heap_before_end);
1717 ATF_TC_HEAD(gethostname_heap_before_end, tc)
1718 {
1719 	atf_tc_set_md_var(tc, "require.user", "root");
1720 }
1721 ATF_TC_BODY(gethostname_heap_before_end, tc)
1722 {
1723 #define BUF __stack.__buf
1724 	struct {
1725 		uint8_t padding_l;
1726 		unsigned char * __buf;
1727 		uint8_t padding_r;
1728 	} __stack;
1729 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (17);
1730 	const size_t __len = 17 - 1;
1731 	const size_t __idx __unused = __len - 1;
1732 
1733 	dhost_jail();
1734 	__stack.__buf = malloc(__bufsz);
1735 
1736 	gethostname(__stack.__buf, __len);
1737 #undef BUF
1738 
1739 }
1740 
1741 ATF_TC(gethostname_heap_end);
1742 ATF_TC_HEAD(gethostname_heap_end, tc)
1743 {
1744 	atf_tc_set_md_var(tc, "require.user", "root");
1745 }
1746 ATF_TC_BODY(gethostname_heap_end, tc)
1747 {
1748 #define BUF __stack.__buf
1749 	struct {
1750 		uint8_t padding_l;
1751 		unsigned char * __buf;
1752 		uint8_t padding_r;
1753 	} __stack;
1754 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (17);
1755 	const size_t __len = 17;
1756 	const size_t __idx __unused = __len - 1;
1757 
1758 	dhost_jail();
1759 	__stack.__buf = malloc(__bufsz);
1760 
1761 	gethostname(__stack.__buf, __len);
1762 #undef BUF
1763 
1764 }
1765 
1766 ATF_TC(gethostname_heap_after_end);
1767 ATF_TC_HEAD(gethostname_heap_after_end, tc)
1768 {
1769 	atf_tc_set_md_var(tc, "require.user", "root");
1770 }
1771 ATF_TC_BODY(gethostname_heap_after_end, tc)
1772 {
1773 #define BUF __stack.__buf
1774 	struct {
1775 		uint8_t padding_l;
1776 		unsigned char * __buf;
1777 		uint8_t padding_r;
1778 	} __stack;
1779 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (17);
1780 	const size_t __len = 17 + 1;
1781 	const size_t __idx __unused = __len - 1;
1782 	pid_t __child;
1783 	int __status;
1784 
1785 	dhost_jail();
1786 	__child = fork();
1787 	ATF_REQUIRE(__child >= 0);
1788 	if (__child > 0)
1789 		goto monitor;
1790 
1791 	/* Child */
1792 	disable_coredumps();
1793 	__stack.__buf = malloc(__bufsz);
1794 
1795 	gethostname(__stack.__buf, __len);
1796 	_exit(EX_SOFTWARE);	/* Should have aborted. */
1797 
1798 monitor:
1799 	while (waitpid(__child, &__status, 0) != __child) {
1800 		ATF_REQUIRE_EQ(EINTR, errno);
1801 	}
1802 
1803 	if (!WIFSIGNALED(__status)) {
1804 		switch (WEXITSTATUS(__status)) {
1805 		case EX_SOFTWARE:
1806 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
1807 			break;
1808 		case EX_OSERR:
1809 			atf_tc_fail("setrlimit(2) failed");
1810 			break;
1811 		default:
1812 			atf_tc_fail("child exited with status %d",
1813 			    WEXITSTATUS(__status));
1814 		}
1815 	} else {
1816 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
1817 	}
1818 #undef BUF
1819 
1820 }
1821 
1822 ATF_TC(getlogin_r_before_end);
1823 ATF_TC_HEAD(getlogin_r_before_end, tc)
1824 {
1825 }
1826 ATF_TC_BODY(getlogin_r_before_end, tc)
1827 {
1828 #define BUF &__stack.__buf
1829 	struct {
1830 		uint8_t padding_l;
1831 		unsigned char __buf[MAXLOGNAME + 1];
1832 		uint8_t padding_r;
1833 	} __stack;
1834 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1835 	const size_t __len = MAXLOGNAME + 1 - 1;
1836 	const size_t __idx __unused = __len - 1;
1837 
1838 	getlogin_r(__stack.__buf, __len);
1839 #undef BUF
1840 
1841 }
1842 
1843 ATF_TC(getlogin_r_end);
1844 ATF_TC_HEAD(getlogin_r_end, tc)
1845 {
1846 }
1847 ATF_TC_BODY(getlogin_r_end, tc)
1848 {
1849 #define BUF &__stack.__buf
1850 	struct {
1851 		uint8_t padding_l;
1852 		unsigned char __buf[MAXLOGNAME + 1];
1853 		uint8_t padding_r;
1854 	} __stack;
1855 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1856 	const size_t __len = MAXLOGNAME + 1;
1857 	const size_t __idx __unused = __len - 1;
1858 
1859 	getlogin_r(__stack.__buf, __len);
1860 #undef BUF
1861 
1862 }
1863 
1864 ATF_TC(getlogin_r_heap_before_end);
1865 ATF_TC_HEAD(getlogin_r_heap_before_end, tc)
1866 {
1867 }
1868 ATF_TC_BODY(getlogin_r_heap_before_end, tc)
1869 {
1870 #define BUF __stack.__buf
1871 	struct {
1872 		uint8_t padding_l;
1873 		unsigned char * __buf;
1874 		uint8_t padding_r;
1875 	} __stack;
1876 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (MAXLOGNAME + 1);
1877 	const size_t __len = MAXLOGNAME + 1 - 1;
1878 	const size_t __idx __unused = __len - 1;
1879 
1880 	__stack.__buf = malloc(__bufsz);
1881 
1882 	getlogin_r(__stack.__buf, __len);
1883 #undef BUF
1884 
1885 }
1886 
1887 ATF_TC(getlogin_r_heap_end);
1888 ATF_TC_HEAD(getlogin_r_heap_end, tc)
1889 {
1890 }
1891 ATF_TC_BODY(getlogin_r_heap_end, tc)
1892 {
1893 #define BUF __stack.__buf
1894 	struct {
1895 		uint8_t padding_l;
1896 		unsigned char * __buf;
1897 		uint8_t padding_r;
1898 	} __stack;
1899 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (MAXLOGNAME + 1);
1900 	const size_t __len = MAXLOGNAME + 1;
1901 	const size_t __idx __unused = __len - 1;
1902 
1903 	__stack.__buf = malloc(__bufsz);
1904 
1905 	getlogin_r(__stack.__buf, __len);
1906 #undef BUF
1907 
1908 }
1909 
1910 ATF_TC(getlogin_r_heap_after_end);
1911 ATF_TC_HEAD(getlogin_r_heap_after_end, tc)
1912 {
1913 }
1914 ATF_TC_BODY(getlogin_r_heap_after_end, tc)
1915 {
1916 #define BUF __stack.__buf
1917 	struct {
1918 		uint8_t padding_l;
1919 		unsigned char * __buf;
1920 		uint8_t padding_r;
1921 	} __stack;
1922 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (MAXLOGNAME + 1);
1923 	const size_t __len = MAXLOGNAME + 1 + 1;
1924 	const size_t __idx __unused = __len - 1;
1925 	pid_t __child;
1926 	int __status;
1927 
1928 	__child = fork();
1929 	ATF_REQUIRE(__child >= 0);
1930 	if (__child > 0)
1931 		goto monitor;
1932 
1933 	/* Child */
1934 	disable_coredumps();
1935 	__stack.__buf = malloc(__bufsz);
1936 
1937 	getlogin_r(__stack.__buf, __len);
1938 	_exit(EX_SOFTWARE);	/* Should have aborted. */
1939 
1940 monitor:
1941 	while (waitpid(__child, &__status, 0) != __child) {
1942 		ATF_REQUIRE_EQ(EINTR, errno);
1943 	}
1944 
1945 	if (!WIFSIGNALED(__status)) {
1946 		switch (WEXITSTATUS(__status)) {
1947 		case EX_SOFTWARE:
1948 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
1949 			break;
1950 		case EX_OSERR:
1951 			atf_tc_fail("setrlimit(2) failed");
1952 			break;
1953 		default:
1954 			atf_tc_fail("child exited with status %d",
1955 			    WEXITSTATUS(__status));
1956 		}
1957 	} else {
1958 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
1959 	}
1960 #undef BUF
1961 
1962 }
1963 
1964 ATF_TC(ttyname_r_before_end);
1965 ATF_TC_HEAD(ttyname_r_before_end, tc)
1966 {
1967 }
1968 ATF_TC_BODY(ttyname_r_before_end, tc)
1969 {
1970 #define BUF &__stack.__buf
1971 	struct {
1972 		uint8_t padding_l;
1973 		unsigned char __buf[42];
1974 		uint8_t padding_r;
1975 	} __stack;
1976 	const size_t __bufsz __unused = sizeof(__stack.__buf);
1977 	const size_t __len = 42 - 1;
1978 	const size_t __idx __unused = __len - 1;
1979 	int fd;
1980 
1981 	fd = STDIN_FILENO;
1982 	if (!isatty(fd))
1983 		atf_tc_skip("stdin is not an fd");
1984 
1985 	ttyname_r(fd, __stack.__buf, __len);
1986 #undef BUF
1987 
1988 }
1989 
1990 ATF_TC(ttyname_r_end);
1991 ATF_TC_HEAD(ttyname_r_end, tc)
1992 {
1993 }
1994 ATF_TC_BODY(ttyname_r_end, tc)
1995 {
1996 #define BUF &__stack.__buf
1997 	struct {
1998 		uint8_t padding_l;
1999 		unsigned char __buf[42];
2000 		uint8_t padding_r;
2001 	} __stack;
2002 	const size_t __bufsz __unused = sizeof(__stack.__buf);
2003 	const size_t __len = 42;
2004 	const size_t __idx __unused = __len - 1;
2005 	int fd;
2006 
2007 	fd = STDIN_FILENO;
2008 	if (!isatty(fd))
2009 		atf_tc_skip("stdin is not an fd");
2010 
2011 	ttyname_r(fd, __stack.__buf, __len);
2012 #undef BUF
2013 
2014 }
2015 
2016 ATF_TC(ttyname_r_heap_before_end);
2017 ATF_TC_HEAD(ttyname_r_heap_before_end, tc)
2018 {
2019 }
2020 ATF_TC_BODY(ttyname_r_heap_before_end, tc)
2021 {
2022 #define BUF __stack.__buf
2023 	struct {
2024 		uint8_t padding_l;
2025 		unsigned char * __buf;
2026 		uint8_t padding_r;
2027 	} __stack;
2028 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
2029 	const size_t __len = 42 - 1;
2030 	const size_t __idx __unused = __len - 1;
2031 	int fd;
2032 
2033 	fd = STDIN_FILENO;
2034 	if (!isatty(fd))
2035 		atf_tc_skip("stdin is not an fd");
2036 
2037 	__stack.__buf = malloc(__bufsz);
2038 
2039 	ttyname_r(fd, __stack.__buf, __len);
2040 #undef BUF
2041 
2042 }
2043 
2044 ATF_TC(ttyname_r_heap_end);
2045 ATF_TC_HEAD(ttyname_r_heap_end, tc)
2046 {
2047 }
2048 ATF_TC_BODY(ttyname_r_heap_end, tc)
2049 {
2050 #define BUF __stack.__buf
2051 	struct {
2052 		uint8_t padding_l;
2053 		unsigned char * __buf;
2054 		uint8_t padding_r;
2055 	} __stack;
2056 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
2057 	const size_t __len = 42;
2058 	const size_t __idx __unused = __len - 1;
2059 	int fd;
2060 
2061 	fd = STDIN_FILENO;
2062 	if (!isatty(fd))
2063 		atf_tc_skip("stdin is not an fd");
2064 
2065 	__stack.__buf = malloc(__bufsz);
2066 
2067 	ttyname_r(fd, __stack.__buf, __len);
2068 #undef BUF
2069 
2070 }
2071 
2072 ATF_TC(ttyname_r_heap_after_end);
2073 ATF_TC_HEAD(ttyname_r_heap_after_end, tc)
2074 {
2075 }
2076 ATF_TC_BODY(ttyname_r_heap_after_end, tc)
2077 {
2078 #define BUF __stack.__buf
2079 	struct {
2080 		uint8_t padding_l;
2081 		unsigned char * __buf;
2082 		uint8_t padding_r;
2083 	} __stack;
2084 	const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
2085 	const size_t __len = 42 + 1;
2086 	const size_t __idx __unused = __len - 1;
2087 	pid_t __child;
2088 	int __status;
2089 	int fd;
2090 
2091 	fd = STDIN_FILENO;
2092 	if (!isatty(fd))
2093 		atf_tc_skip("stdin is not an fd");
2094 
2095 	__child = fork();
2096 	ATF_REQUIRE(__child >= 0);
2097 	if (__child > 0)
2098 		goto monitor;
2099 
2100 	/* Child */
2101 	disable_coredumps();
2102 	__stack.__buf = malloc(__bufsz);
2103 
2104 	ttyname_r(fd, __stack.__buf, __len);
2105 	_exit(EX_SOFTWARE);	/* Should have aborted. */
2106 
2107 monitor:
2108 	while (waitpid(__child, &__status, 0) != __child) {
2109 		ATF_REQUIRE_EQ(EINTR, errno);
2110 	}
2111 
2112 	if (!WIFSIGNALED(__status)) {
2113 		switch (WEXITSTATUS(__status)) {
2114 		case EX_SOFTWARE:
2115 			atf_tc_fail("FORTIFY_SOURCE failed to abort");
2116 			break;
2117 		case EX_OSERR:
2118 			atf_tc_fail("setrlimit(2) failed");
2119 			break;
2120 		default:
2121 			atf_tc_fail("child exited with status %d",
2122 			    WEXITSTATUS(__status));
2123 		}
2124 	} else {
2125 		ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
2126 	}
2127 #undef BUF
2128 
2129 }
2130 
2131 ATF_TP_ADD_TCS(tp)
2132 {
2133 	ATF_TP_ADD_TC(tp, getcwd_before_end);
2134 	ATF_TP_ADD_TC(tp, getcwd_end);
2135 	ATF_TP_ADD_TC(tp, getcwd_heap_before_end);
2136 	ATF_TP_ADD_TC(tp, getcwd_heap_end);
2137 	ATF_TP_ADD_TC(tp, getcwd_heap_after_end);
2138 	ATF_TP_ADD_TC(tp, getgrouplist_before_end);
2139 	ATF_TP_ADD_TC(tp, getgrouplist_end);
2140 	ATF_TP_ADD_TC(tp, getgrouplist_heap_before_end);
2141 	ATF_TP_ADD_TC(tp, getgrouplist_heap_end);
2142 	ATF_TP_ADD_TC(tp, getgrouplist_heap_after_end);
2143 	ATF_TP_ADD_TC(tp, getgroups_before_end);
2144 	ATF_TP_ADD_TC(tp, getgroups_end);
2145 	ATF_TP_ADD_TC(tp, getgroups_heap_before_end);
2146 	ATF_TP_ADD_TC(tp, getgroups_heap_end);
2147 	ATF_TP_ADD_TC(tp, getgroups_heap_after_end);
2148 	ATF_TP_ADD_TC(tp, getloginclass_before_end);
2149 	ATF_TP_ADD_TC(tp, getloginclass_end);
2150 	ATF_TP_ADD_TC(tp, getloginclass_heap_before_end);
2151 	ATF_TP_ADD_TC(tp, getloginclass_heap_end);
2152 	ATF_TP_ADD_TC(tp, getloginclass_heap_after_end);
2153 	ATF_TP_ADD_TC(tp, pread_before_end);
2154 	ATF_TP_ADD_TC(tp, pread_end);
2155 	ATF_TP_ADD_TC(tp, pread_heap_before_end);
2156 	ATF_TP_ADD_TC(tp, pread_heap_end);
2157 	ATF_TP_ADD_TC(tp, pread_heap_after_end);
2158 	ATF_TP_ADD_TC(tp, read_before_end);
2159 	ATF_TP_ADD_TC(tp, read_end);
2160 	ATF_TP_ADD_TC(tp, read_heap_before_end);
2161 	ATF_TP_ADD_TC(tp, read_heap_end);
2162 	ATF_TP_ADD_TC(tp, read_heap_after_end);
2163 	ATF_TP_ADD_TC(tp, readlink_before_end);
2164 	ATF_TP_ADD_TC(tp, readlink_end);
2165 	ATF_TP_ADD_TC(tp, readlink_heap_before_end);
2166 	ATF_TP_ADD_TC(tp, readlink_heap_end);
2167 	ATF_TP_ADD_TC(tp, readlink_heap_after_end);
2168 	ATF_TP_ADD_TC(tp, readlinkat_before_end);
2169 	ATF_TP_ADD_TC(tp, readlinkat_end);
2170 	ATF_TP_ADD_TC(tp, readlinkat_heap_before_end);
2171 	ATF_TP_ADD_TC(tp, readlinkat_heap_end);
2172 	ATF_TP_ADD_TC(tp, readlinkat_heap_after_end);
2173 	ATF_TP_ADD_TC(tp, getdomainname_before_end);
2174 	ATF_TP_ADD_TC(tp, getdomainname_end);
2175 	ATF_TP_ADD_TC(tp, getdomainname_heap_before_end);
2176 	ATF_TP_ADD_TC(tp, getdomainname_heap_end);
2177 	ATF_TP_ADD_TC(tp, getdomainname_heap_after_end);
2178 	ATF_TP_ADD_TC(tp, getentropy_before_end);
2179 	ATF_TP_ADD_TC(tp, getentropy_end);
2180 	ATF_TP_ADD_TC(tp, getentropy_heap_before_end);
2181 	ATF_TP_ADD_TC(tp, getentropy_heap_end);
2182 	ATF_TP_ADD_TC(tp, getentropy_heap_after_end);
2183 	ATF_TP_ADD_TC(tp, gethostname_before_end);
2184 	ATF_TP_ADD_TC(tp, gethostname_end);
2185 	ATF_TP_ADD_TC(tp, gethostname_heap_before_end);
2186 	ATF_TP_ADD_TC(tp, gethostname_heap_end);
2187 	ATF_TP_ADD_TC(tp, gethostname_heap_after_end);
2188 	ATF_TP_ADD_TC(tp, getlogin_r_before_end);
2189 	ATF_TP_ADD_TC(tp, getlogin_r_end);
2190 	ATF_TP_ADD_TC(tp, getlogin_r_heap_before_end);
2191 	ATF_TP_ADD_TC(tp, getlogin_r_heap_end);
2192 	ATF_TP_ADD_TC(tp, getlogin_r_heap_after_end);
2193 	ATF_TP_ADD_TC(tp, ttyname_r_before_end);
2194 	ATF_TP_ADD_TC(tp, ttyname_r_end);
2195 	ATF_TP_ADD_TC(tp, ttyname_r_heap_before_end);
2196 	ATF_TP_ADD_TC(tp, ttyname_r_heap_end);
2197 	ATF_TP_ADD_TC(tp, ttyname_r_heap_after_end);
2198 	return (atf_no_error());
2199 }
2200