root/lib/libc/tests/secure/fortify_string_test.c
/* @generated by `generate-fortify-tests.lua "string"` */

#define _FORTIFY_SOURCE 2
#define TMPFILE_SIZE    (1024 * 32)

#include <sys/param.h>
#include <sys/jail.h>
#include <sys/random.h>
#include <sys/resource.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sysexits.h>
#include <unistd.h>
#include <wchar.h>
#include <atf-c.h>

static FILE * __unused
new_fp(size_t __len)
{
        static char fpbuf[LINE_MAX];
        FILE *fp;

        ATF_REQUIRE(__len <= sizeof(fpbuf));

        memset(fpbuf, 'A', sizeof(fpbuf) - 1);
        fpbuf[sizeof(fpbuf) - 1] = '\0';

        fp = fmemopen(fpbuf, sizeof(fpbuf), "rb");
        ATF_REQUIRE(fp != NULL);

        return (fp);
}

/*
 * Create a new symlink to use for readlink(2) style tests, we'll just use a
 * random target name to have something interesting to look at.
 */
static const char * __unused
new_symlink(size_t __len)
{
        static const char linkname[] = "link";
        char target[MAXNAMLEN];
        int error;

        ATF_REQUIRE(__len <= sizeof(target));

        arc4random_buf(target, sizeof(target));

        error = unlink(linkname);
        ATF_REQUIRE(error == 0 || errno == ENOENT);

        error = symlink(target, linkname);
        ATF_REQUIRE(error == 0);

        return (linkname);
}

/*
 * For our purposes, first descriptor will be the reader; we'll send both
 * raw data and a control message over it so that the result can be used for
 * any of our recv*() tests.
 */
static void __unused
new_socket(int sock[2])
{
        unsigned char ctrl[CMSG_SPACE(sizeof(int))] = { 0 };
        static char sockbuf[256];
        ssize_t rv;
        size_t total = 0;
        struct msghdr hdr = { 0 };
        struct cmsghdr *cmsg;
        int error, fd;

        error = socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
        ATF_REQUIRE(error == 0);

        while (total != sizeof(sockbuf)) {
                rv = send(sock[1], &sockbuf[total], sizeof(sockbuf) - total, 0);

                ATF_REQUIRE_MSG(rv > 0,
                    "expected bytes sent, got %zd with %zu left (size %zu, total %zu)",
                    rv, sizeof(sockbuf) - total, sizeof(sockbuf), total);
                ATF_REQUIRE_MSG(total + (size_t)rv <= sizeof(sockbuf),
                    "%zd exceeds total %zu", rv, sizeof(sockbuf));
                total += rv;
        }

        hdr.msg_control = ctrl;
        hdr.msg_controllen = sizeof(ctrl);

        cmsg = CMSG_FIRSTHDR(&hdr);
        cmsg->cmsg_level = SOL_SOCKET;
        cmsg->cmsg_type = SCM_RIGHTS;
        cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
        fd = STDIN_FILENO;
        memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd));

        error = sendmsg(sock[1], &hdr, 0);
        ATF_REQUIRE(error != -1);
}

/*
 * Constructs a tmpfile that we can use for testing read(2) and friends.
 */
static int __unused
new_tmpfile(void)
{
        char buf[1024];
        ssize_t rv;
        size_t written;
        int fd;

        fd = open("tmpfile", O_RDWR | O_CREAT | O_TRUNC, 0644);
        ATF_REQUIRE(fd >= 0);

        written = 0;
        while (written < TMPFILE_SIZE) {
                rv = write(fd, buf, sizeof(buf));
                ATF_REQUIRE(rv > 0);

                written += rv;
        }

        ATF_REQUIRE_EQ(0, lseek(fd, 0, SEEK_SET));
        return (fd);
}

static void
disable_coredumps(void)
{
        struct rlimit rl = { 0 };

        if (setrlimit(RLIMIT_CORE, &rl) == -1)
                _exit(EX_OSERR);
}

/*
 * Replaces stdin with a file that we can actually read from, for tests where
 * we want a FILE * or fd that we can get data from.
 */
static void __unused
replace_stdin(void)
{
        int fd;

        fd = new_tmpfile();

        (void)dup2(fd, STDIN_FILENO);
        if (fd != STDIN_FILENO)
                close(fd);
}

ATF_TC(memcpy_before_end);
ATF_TC_HEAD(memcpy_before_end, tc)
{
}
ATF_TC_BODY(memcpy_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        memcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(memcpy_end);
ATF_TC_HEAD(memcpy_end, tc)
{
}
ATF_TC_BODY(memcpy_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        memcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(memcpy_heap_before_end);
ATF_TC_HEAD(memcpy_heap_before_end, tc)
{
}
ATF_TC_BODY(memcpy_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        __stack.__buf = malloc(__bufsz);

        memcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(memcpy_heap_end);
ATF_TC_HEAD(memcpy_heap_end, tc)
{
}
ATF_TC_BODY(memcpy_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        __stack.__buf = malloc(__bufsz);

        memcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(memcpy_heap_after_end);
ATF_TC_HEAD(memcpy_heap_after_end, tc)
{
}
ATF_TC_BODY(memcpy_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;
        char src[__len + 10];

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);

        memcpy(__stack.__buf, src, __len);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(mempcpy_before_end);
ATF_TC_HEAD(mempcpy_before_end, tc)
{
}
ATF_TC_BODY(mempcpy_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        mempcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(mempcpy_end);
ATF_TC_HEAD(mempcpy_end, tc)
{
}
ATF_TC_BODY(mempcpy_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        mempcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(mempcpy_heap_before_end);
ATF_TC_HEAD(mempcpy_heap_before_end, tc)
{
}
ATF_TC_BODY(mempcpy_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        __stack.__buf = malloc(__bufsz);

        mempcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(mempcpy_heap_end);
ATF_TC_HEAD(mempcpy_heap_end, tc)
{
}
ATF_TC_BODY(mempcpy_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        __stack.__buf = malloc(__bufsz);

        mempcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(mempcpy_heap_after_end);
ATF_TC_HEAD(mempcpy_heap_after_end, tc)
{
}
ATF_TC_BODY(mempcpy_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;
        char src[__len + 10];

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);

        mempcpy(__stack.__buf, src, __len);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(memmove_before_end);
ATF_TC_HEAD(memmove_before_end, tc)
{
}
ATF_TC_BODY(memmove_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        memmove(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(memmove_end);
ATF_TC_HEAD(memmove_end, tc)
{
}
ATF_TC_BODY(memmove_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        memmove(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(memmove_heap_before_end);
ATF_TC_HEAD(memmove_heap_before_end, tc)
{
}
ATF_TC_BODY(memmove_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        __stack.__buf = malloc(__bufsz);

        memmove(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(memmove_heap_end);
ATF_TC_HEAD(memmove_heap_end, tc)
{
}
ATF_TC_BODY(memmove_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len + 10];

        __stack.__buf = malloc(__bufsz);

        memmove(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(memmove_heap_after_end);
ATF_TC_HEAD(memmove_heap_after_end, tc)
{
}
ATF_TC_BODY(memmove_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;
        char src[__len + 10];

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);

        memmove(__stack.__buf, src, __len);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(memset_before_end);
ATF_TC_HEAD(memset_before_end, tc)
{
}
ATF_TC_BODY(memset_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;

        memset(__stack.__buf, 0, __len);
#undef BUF

}

ATF_TC(memset_end);
ATF_TC_HEAD(memset_end, tc)
{
}
ATF_TC_BODY(memset_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;

        memset(__stack.__buf, 0, __len);
#undef BUF

}

ATF_TC(memset_heap_before_end);
ATF_TC_HEAD(memset_heap_before_end, tc)
{
}
ATF_TC_BODY(memset_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;

        __stack.__buf = malloc(__bufsz);

        memset(__stack.__buf, 0, __len);
#undef BUF

}

ATF_TC(memset_heap_end);
ATF_TC_HEAD(memset_heap_end, tc)
{
}
ATF_TC_BODY(memset_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;

        __stack.__buf = malloc(__bufsz);

        memset(__stack.__buf, 0, __len);
#undef BUF

}

ATF_TC(memset_heap_after_end);
ATF_TC_HEAD(memset_heap_after_end, tc)
{
}
ATF_TC_BODY(memset_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);

        memset(__stack.__buf, 0, __len);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(memset_explicit_before_end);
ATF_TC_HEAD(memset_explicit_before_end, tc)
{
}
ATF_TC_BODY(memset_explicit_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;

        memset_explicit(__stack.__buf, 0, __len);
#undef BUF

}

ATF_TC(memset_explicit_end);
ATF_TC_HEAD(memset_explicit_end, tc)
{
}
ATF_TC_BODY(memset_explicit_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;

        memset_explicit(__stack.__buf, 0, __len);
#undef BUF

}

ATF_TC(memset_explicit_heap_before_end);
ATF_TC_HEAD(memset_explicit_heap_before_end, tc)
{
}
ATF_TC_BODY(memset_explicit_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;

        __stack.__buf = malloc(__bufsz);

        memset_explicit(__stack.__buf, 0, __len);
#undef BUF

}

ATF_TC(memset_explicit_heap_end);
ATF_TC_HEAD(memset_explicit_heap_end, tc)
{
}
ATF_TC_BODY(memset_explicit_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;

        __stack.__buf = malloc(__bufsz);

        memset_explicit(__stack.__buf, 0, __len);
#undef BUF

}

ATF_TC(memset_explicit_heap_after_end);
ATF_TC_HEAD(memset_explicit_heap_after_end, tc)
{
}
ATF_TC_BODY(memset_explicit_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);

        memset_explicit(__stack.__buf, 0, __len);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(stpcpy_before_end);
ATF_TC_HEAD(stpcpy_before_end, tc)
{
}
ATF_TC_BODY(stpcpy_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        stpcpy(__stack.__buf, src);
#undef BUF

}

ATF_TC(stpcpy_end);
ATF_TC_HEAD(stpcpy_end, tc)
{
}
ATF_TC_BODY(stpcpy_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        stpcpy(__stack.__buf, src);
#undef BUF

}

ATF_TC(stpcpy_heap_before_end);
ATF_TC_HEAD(stpcpy_heap_before_end, tc)
{
}
ATF_TC_BODY(stpcpy_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        stpcpy(__stack.__buf, src);
#undef BUF

}

ATF_TC(stpcpy_heap_end);
ATF_TC_HEAD(stpcpy_heap_end, tc)
{
}
ATF_TC_BODY(stpcpy_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        stpcpy(__stack.__buf, src);
#undef BUF

}

ATF_TC(stpcpy_heap_after_end);
ATF_TC_HEAD(stpcpy_heap_after_end, tc)
{
}
ATF_TC_BODY(stpcpy_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;
        char src[__len];

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        stpcpy(__stack.__buf, src);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(stpncpy_before_end);
ATF_TC_HEAD(stpncpy_before_end, tc)
{
}
ATF_TC_BODY(stpncpy_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        stpncpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(stpncpy_end);
ATF_TC_HEAD(stpncpy_end, tc)
{
}
ATF_TC_BODY(stpncpy_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        stpncpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(stpncpy_heap_before_end);
ATF_TC_HEAD(stpncpy_heap_before_end, tc)
{
}
ATF_TC_BODY(stpncpy_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        stpncpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(stpncpy_heap_end);
ATF_TC_HEAD(stpncpy_heap_end, tc)
{
}
ATF_TC_BODY(stpncpy_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        stpncpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(stpncpy_heap_after_end);
ATF_TC_HEAD(stpncpy_heap_after_end, tc)
{
}
ATF_TC_BODY(stpncpy_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;
        char src[__len];

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        stpncpy(__stack.__buf, src, __len);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(strcat_before_end);
ATF_TC_HEAD(strcat_before_end, tc)
{
}
ATF_TC_BODY(strcat_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strcat(__stack.__buf, src);
#undef BUF

}

ATF_TC(strcat_end);
ATF_TC_HEAD(strcat_end, tc)
{
}
ATF_TC_BODY(strcat_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strcat(__stack.__buf, src);
#undef BUF

}

ATF_TC(strcat_heap_before_end);
ATF_TC_HEAD(strcat_heap_before_end, tc)
{
}
ATF_TC_BODY(strcat_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strcat(__stack.__buf, src);
#undef BUF

}

ATF_TC(strcat_heap_end);
ATF_TC_HEAD(strcat_heap_end, tc)
{
}
ATF_TC_BODY(strcat_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strcat(__stack.__buf, src);
#undef BUF

}

ATF_TC(strcat_heap_after_end);
ATF_TC_HEAD(strcat_heap_after_end, tc)
{
}
ATF_TC_BODY(strcat_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;
        char src[__len];

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strcat(__stack.__buf, src);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(strlcat_before_end);
ATF_TC_HEAD(strlcat_before_end, tc)
{
}
ATF_TC_BODY(strlcat_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strlcat(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strlcat_end);
ATF_TC_HEAD(strlcat_end, tc)
{
}
ATF_TC_BODY(strlcat_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strlcat(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strlcat_heap_before_end);
ATF_TC_HEAD(strlcat_heap_before_end, tc)
{
}
ATF_TC_BODY(strlcat_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strlcat(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strlcat_heap_end);
ATF_TC_HEAD(strlcat_heap_end, tc)
{
}
ATF_TC_BODY(strlcat_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strlcat(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strlcat_heap_after_end);
ATF_TC_HEAD(strlcat_heap_after_end, tc)
{
}
ATF_TC_BODY(strlcat_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;
        char src[__len];

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strlcat(__stack.__buf, src, __len);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(strncat_before_end);
ATF_TC_HEAD(strncat_before_end, tc)
{
}
ATF_TC_BODY(strncat_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strncat(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strncat_end);
ATF_TC_HEAD(strncat_end, tc)
{
}
ATF_TC_BODY(strncat_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strncat(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strncat_heap_before_end);
ATF_TC_HEAD(strncat_heap_before_end, tc)
{
}
ATF_TC_BODY(strncat_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strncat(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strncat_heap_end);
ATF_TC_HEAD(strncat_heap_end, tc)
{
}
ATF_TC_BODY(strncat_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strncat(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strncat_heap_after_end);
ATF_TC_HEAD(strncat_heap_after_end, tc)
{
}
ATF_TC_BODY(strncat_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;
        char src[__len];

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strncat(__stack.__buf, src, __len);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(strcpy_before_end);
ATF_TC_HEAD(strcpy_before_end, tc)
{
}
ATF_TC_BODY(strcpy_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strcpy(__stack.__buf, src);
#undef BUF

}

ATF_TC(strcpy_end);
ATF_TC_HEAD(strcpy_end, tc)
{
}
ATF_TC_BODY(strcpy_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strcpy(__stack.__buf, src);
#undef BUF

}

ATF_TC(strcpy_heap_before_end);
ATF_TC_HEAD(strcpy_heap_before_end, tc)
{
}
ATF_TC_BODY(strcpy_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strcpy(__stack.__buf, src);
#undef BUF

}

ATF_TC(strcpy_heap_end);
ATF_TC_HEAD(strcpy_heap_end, tc)
{
}
ATF_TC_BODY(strcpy_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strcpy(__stack.__buf, src);
#undef BUF

}

ATF_TC(strcpy_heap_after_end);
ATF_TC_HEAD(strcpy_heap_after_end, tc)
{
}
ATF_TC_BODY(strcpy_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;
        char src[__len];

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strcpy(__stack.__buf, src);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(strlcpy_before_end);
ATF_TC_HEAD(strlcpy_before_end, tc)
{
}
ATF_TC_BODY(strlcpy_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strlcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strlcpy_end);
ATF_TC_HEAD(strlcpy_end, tc)
{
}
ATF_TC_BODY(strlcpy_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strlcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strlcpy_heap_before_end);
ATF_TC_HEAD(strlcpy_heap_before_end, tc)
{
}
ATF_TC_BODY(strlcpy_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strlcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strlcpy_heap_end);
ATF_TC_HEAD(strlcpy_heap_end, tc)
{
}
ATF_TC_BODY(strlcpy_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strlcpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strlcpy_heap_after_end);
ATF_TC_HEAD(strlcpy_heap_after_end, tc)
{
}
ATF_TC_BODY(strlcpy_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;
        char src[__len];

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strlcpy(__stack.__buf, src, __len);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TC(strncpy_before_end);
ATF_TC_HEAD(strncpy_before_end, tc)
{
}
ATF_TC_BODY(strncpy_before_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strncpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strncpy_end);
ATF_TC_HEAD(strncpy_end, tc)
{
}
ATF_TC_BODY(strncpy_end, tc)
{
#define BUF &__stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char __buf[42];
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(__stack.__buf);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strncpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strncpy_heap_before_end);
ATF_TC_HEAD(strncpy_heap_before_end, tc)
{
}
ATF_TC_BODY(strncpy_heap_before_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 - 1;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strncpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strncpy_heap_end);
ATF_TC_HEAD(strncpy_heap_end, tc)
{
}
ATF_TC_BODY(strncpy_heap_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42;
        const size_t __idx __unused = __len - 1;
        char src[__len];

        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strncpy(__stack.__buf, src, __len);
#undef BUF

}

ATF_TC(strncpy_heap_after_end);
ATF_TC_HEAD(strncpy_heap_after_end, tc)
{
}
ATF_TC_BODY(strncpy_heap_after_end, tc)
{
#define BUF __stack.__buf
        struct {
                uint8_t padding_l;
                unsigned char * __buf;
                uint8_t padding_r;
        } __stack;
        const size_t __bufsz __unused = sizeof(*__stack.__buf) * (42);
        const size_t __len = 42 + 1;
        const size_t __idx __unused = __len - 1;
        pid_t __child;
        int __status;
        char src[__len];

        __child = fork();
        ATF_REQUIRE(__child >= 0);
        if (__child > 0)
                goto monitor;

        /* Child */
        disable_coredumps();
        __stack.__buf = malloc(__bufsz);
        memset(__stack.__buf, 0, __len);
        memset(src, 'A', __len - 1);
        src[__len - 1] = '\0';

        strncpy(__stack.__buf, src, __len);
        _exit(EX_SOFTWARE);     /* Should have aborted. */

monitor:
        while (waitpid(__child, &__status, 0) != __child) {
                ATF_REQUIRE_EQ(EINTR, errno);
        }

        if (!WIFSIGNALED(__status)) {
                switch (WEXITSTATUS(__status)) {
                case EX_SOFTWARE:
                        atf_tc_fail("FORTIFY_SOURCE failed to abort");
                        break;
                case EX_OSERR:
                        atf_tc_fail("setrlimit(2) failed");
                        break;
                default:
                        atf_tc_fail("child exited with status %d",
                            WEXITSTATUS(__status));
                }
        } else {
                ATF_REQUIRE_EQ(SIGABRT, WTERMSIG(__status));
        }
#undef BUF

}

ATF_TP_ADD_TCS(tp)
{
        ATF_TP_ADD_TC(tp, memcpy_before_end);
        ATF_TP_ADD_TC(tp, memcpy_end);
        ATF_TP_ADD_TC(tp, memcpy_heap_before_end);
        ATF_TP_ADD_TC(tp, memcpy_heap_end);
        ATF_TP_ADD_TC(tp, memcpy_heap_after_end);
        ATF_TP_ADD_TC(tp, mempcpy_before_end);
        ATF_TP_ADD_TC(tp, mempcpy_end);
        ATF_TP_ADD_TC(tp, mempcpy_heap_before_end);
        ATF_TP_ADD_TC(tp, mempcpy_heap_end);
        ATF_TP_ADD_TC(tp, mempcpy_heap_after_end);
        ATF_TP_ADD_TC(tp, memmove_before_end);
        ATF_TP_ADD_TC(tp, memmove_end);
        ATF_TP_ADD_TC(tp, memmove_heap_before_end);
        ATF_TP_ADD_TC(tp, memmove_heap_end);
        ATF_TP_ADD_TC(tp, memmove_heap_after_end);
        ATF_TP_ADD_TC(tp, memset_before_end);
        ATF_TP_ADD_TC(tp, memset_end);
        ATF_TP_ADD_TC(tp, memset_heap_before_end);
        ATF_TP_ADD_TC(tp, memset_heap_end);
        ATF_TP_ADD_TC(tp, memset_heap_after_end);
        ATF_TP_ADD_TC(tp, memset_explicit_before_end);
        ATF_TP_ADD_TC(tp, memset_explicit_end);
        ATF_TP_ADD_TC(tp, memset_explicit_heap_before_end);
        ATF_TP_ADD_TC(tp, memset_explicit_heap_end);
        ATF_TP_ADD_TC(tp, memset_explicit_heap_after_end);
        ATF_TP_ADD_TC(tp, stpcpy_before_end);
        ATF_TP_ADD_TC(tp, stpcpy_end);
        ATF_TP_ADD_TC(tp, stpcpy_heap_before_end);
        ATF_TP_ADD_TC(tp, stpcpy_heap_end);
        ATF_TP_ADD_TC(tp, stpcpy_heap_after_end);
        ATF_TP_ADD_TC(tp, stpncpy_before_end);
        ATF_TP_ADD_TC(tp, stpncpy_end);
        ATF_TP_ADD_TC(tp, stpncpy_heap_before_end);
        ATF_TP_ADD_TC(tp, stpncpy_heap_end);
        ATF_TP_ADD_TC(tp, stpncpy_heap_after_end);
        ATF_TP_ADD_TC(tp, strcat_before_end);
        ATF_TP_ADD_TC(tp, strcat_end);
        ATF_TP_ADD_TC(tp, strcat_heap_before_end);
        ATF_TP_ADD_TC(tp, strcat_heap_end);
        ATF_TP_ADD_TC(tp, strcat_heap_after_end);
        ATF_TP_ADD_TC(tp, strlcat_before_end);
        ATF_TP_ADD_TC(tp, strlcat_end);
        ATF_TP_ADD_TC(tp, strlcat_heap_before_end);
        ATF_TP_ADD_TC(tp, strlcat_heap_end);
        ATF_TP_ADD_TC(tp, strlcat_heap_after_end);
        ATF_TP_ADD_TC(tp, strncat_before_end);
        ATF_TP_ADD_TC(tp, strncat_end);
        ATF_TP_ADD_TC(tp, strncat_heap_before_end);
        ATF_TP_ADD_TC(tp, strncat_heap_end);
        ATF_TP_ADD_TC(tp, strncat_heap_after_end);
        ATF_TP_ADD_TC(tp, strcpy_before_end);
        ATF_TP_ADD_TC(tp, strcpy_end);
        ATF_TP_ADD_TC(tp, strcpy_heap_before_end);
        ATF_TP_ADD_TC(tp, strcpy_heap_end);
        ATF_TP_ADD_TC(tp, strcpy_heap_after_end);
        ATF_TP_ADD_TC(tp, strlcpy_before_end);
        ATF_TP_ADD_TC(tp, strlcpy_end);
        ATF_TP_ADD_TC(tp, strlcpy_heap_before_end);
        ATF_TP_ADD_TC(tp, strlcpy_heap_end);
        ATF_TP_ADD_TC(tp, strlcpy_heap_after_end);
        ATF_TP_ADD_TC(tp, strncpy_before_end);
        ATF_TP_ADD_TC(tp, strncpy_end);
        ATF_TP_ADD_TC(tp, strncpy_heap_before_end);
        ATF_TP_ADD_TC(tp, strncpy_heap_end);
        ATF_TP_ADD_TC(tp, strncpy_heap_after_end);
        return (atf_no_error());
}