Module Name: src Committed By: christos Date: Thu Jan 23 12:32:39 UTC 2025
Modified Files: src/tests/lib/libexecinfo: Makefile Added Files: src/tests/lib/libexecinfo: t_backtrace_sandbox.c Log Message: new sandbox test (Kyle Evans @ FreeBSD) To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libexecinfo/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/libexecinfo/t_backtrace_sandbox.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/libexecinfo/Makefile diff -u src/tests/lib/libexecinfo/Makefile:1.8 src/tests/lib/libexecinfo/Makefile:1.9 --- src/tests/lib/libexecinfo/Makefile:1.8 Tue Nov 23 18:29:55 2021 +++ src/tests/lib/libexecinfo/Makefile Thu Jan 23 07:32:38 2025 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.8 2021/11/23 23:29:55 thorpej Exp $ +# $NetBSD: Makefile,v 1.9 2025/01/23 12:32:38 christos Exp $ .include <bsd.own.mk> @@ -6,6 +6,7 @@ TESTSDIR= ${TESTSBASE}/lib/libexecinfo TESTS_C+= t_backtrace TESTS_C+= t_sig_backtrace +TESTS_C+= t_backtrace_sandbox STRIPFLAG= LDADD+= -lexecinfo -lelf Added files: Index: src/tests/lib/libexecinfo/t_backtrace_sandbox.c diff -u /dev/null src/tests/lib/libexecinfo/t_backtrace_sandbox.c:1.1 --- /dev/null Thu Jan 23 07:32:39 2025 +++ src/tests/lib/libexecinfo/t_backtrace_sandbox.c Thu Jan 23 07:32:38 2025 @@ -0,0 +1,66 @@ +/* $NetBSD: t_backtrace_sandbox.c,v 1.1 2025/01/23 12:32:38 christos Exp $ */ + +/*- + * Copyright (c) 2025 Kyle Evans <kev...@freebsd.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_backtrace_sandbox.c,v 1.1 2025/01/23 12:32:38 christos Exp $"); + +#include <sys/param.h> +#ifdef __FreeBSD__ +#include <sys/capsicum.h> +#define __arraycount(a) nitems(a) +#endif + +#include <execinfo.h> +#include <signal.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +#include <atf-c.h> + +#define BT_FUNCTIONS 10 + +ATF_TC(backtrace_sandbox); +ATF_TC_HEAD(backtrace_sandbox, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test backtrace_sandbox_init(3) in sandbox"); +#ifndef __FreeBSD__ + atf_tc_set_md_var(tc, "require.user", "root"); +#endif +} + +ATF_TC_BODY(backtrace_sandbox, tc) +{ + void *addr[BT_FUNCTIONS]; + char **syms; + size_t frames; + + frames = backtrace(addr, __arraycount(addr)); + ATF_REQUIRE(frames > 0); + + syms = backtrace_symbols_fmt(addr, frames, "%n"); + ATF_REQUIRE(strcmp(syms[0], "atfu_backtrace_sandbox_body") == 0); + + backtrace_sandbox_init(); +#ifdef __FreeBSD__ + cap_enter(); +#else + ATF_REQUIRE(chroot("/tmp") == 0); +#endif + + syms = backtrace_symbols_fmt(addr, frames, "%n"); + ATF_REQUIRE(strcmp(syms[0], "atfu_backtrace_sandbox_body") == 0); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, backtrace_sandbox); + + return atf_no_error(); +}