From aff0606d38fdb75829f084795c39be0d6123f047 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Sun, 20 Jul 2025 18:56:44 +0200 Subject: [PATCH] FreeBSD regtest: add a testcase for exterrctl This is a function for libc internal use only, so this test doesn't really add much compared to the scalar test. --- .gitignore | 1 + configure.ac | 5 ++++- memcheck/tests/freebsd/Makefile.am | 9 +++++++++ memcheck/tests/freebsd/exterrctl.cpp | 20 +++++++++++++++++++ memcheck/tests/freebsd/exterrctl.stderr.exp | 22 +++++++++++++++++++++ memcheck/tests/freebsd/exterrctl.vgtest | 3 +++ 6 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 memcheck/tests/freebsd/exterrctl.cpp create mode 100644 memcheck/tests/freebsd/exterrctl.stderr.exp create mode 100644 memcheck/tests/freebsd/exterrctl.vgtest diff --git a/.gitignore b/.gitignore index 0da54a7eb..0283b8d5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1434,6 +1434,7 @@ /memcheck/tests/freebsd/eventfd1 /memcheck/tests/freebsd/eventfd2 /memcheck/tests/freebsd/extattr +/memcheck/tests/freebsd/exterrctl /memcheck/tests/freebsd/fbsd278566 /memcheck/tests/freebsd/fchroot /memcheck/tests/freebsd/fexecve diff --git a/configure.ac b/configure.ac index d64782728..804493c2f 100755 --- a/configure.ac +++ b/configure.ac @@ -5008,7 +5008,8 @@ AC_CHECK_FUNCS([ \ getrlimitusage \ timer_delete \ fchroot \ - setcred + setcred \ + exterrctl ]) # AC_CHECK_LIB adds any library found to the variable LIBS, and links these @@ -5070,6 +5071,8 @@ AM_CONDITIONAL([HAVE_FCHROOT], [test x$ac_cv_func_fchroot = xyes]) AM_CONDITIONAL([HAVE_SETCRED], [test x$ac_cv_func_setcred = xyes]) +AM_CONDITIONAL([HAVE_EXTERRCTL], + [test x$ac_cv_func_exterrctl = xyes]) if test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \ -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX \ diff --git a/memcheck/tests/freebsd/Makefile.am b/memcheck/tests/freebsd/Makefile.am index d96cde1b1..0f00d67a4 100644 --- a/memcheck/tests/freebsd/Makefile.am +++ b/memcheck/tests/freebsd/Makefile.am @@ -51,6 +51,8 @@ EXTRA_DIST = \ eventfd2.stderr.exp \ extattr.vgtest \ extattr.stderr.exp \ + exterrctl.vgtest \ + exterrctl.stderr.exp \ fbsd278566.vgtest \ fbsd278566.stderr.exp \ fchroot.vgtest \ @@ -183,6 +185,10 @@ if HAVE_AIO_READV check_PROGRAMS += aiov endif +if HAVE_EXTERRCTL +check_PROGRAMS += exterrctl +endif + if HAVE_FCHROOT check_PROGRAMS += fchroot fchroot_SOURCES = fchroot.cpp @@ -236,6 +242,9 @@ delete_sized_mismatch_CXXFLAGS = ${AM_CXXFLAGS} --std=c++14 delete_sized_mismatch_SOURCES = delete_sized_mismatch.cpp errno_aligned_allocs_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_NON_POWER_OF_TWO_ALIGNMENT@ extattr_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_UNUSED_BUT_SET_VARIABLE@ @FLAG_W_NO_UNINITIALIZED@ @FLAG_W_NO_USE_AFTER_FREE@ +if HAVE_EXTERRCTL +exterrctl_SOURCES = exterrctl.cpp +endif get_set_login_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_USE_AFTER_FREE@ getfh_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_USE_AFTER_FREE@ getfsstat_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_UNINITIALIZED@ @FLAG_W_NO_USE_AFTER_FREE@ diff --git a/memcheck/tests/freebsd/exterrctl.cpp b/memcheck/tests/freebsd/exterrctl.cpp new file mode 100644 index 000000000..c93af3315 --- /dev/null +++ b/memcheck/tests/freebsd/exterrctl.cpp @@ -0,0 +1,20 @@ +#include +#include + +static long x0; + +int main() +{ + // int exterrctl(u_int op, u_int flags, void *ptr); + // op should be 0 or EXTERRCTLF_FORCE (1) + // flags EXTERRCTL_ENABLE EXTERRCTL_DISABLE EXTERRCTL_UD (1 2 3) + // see sys/sys/_uexterror.h for ptr + long *px{static_cast(malloc(2*sizeof(long)))}; + x0 = px[0]; + + char *foo = new char [48+128]; + delete [] foo; + + exterrctl(x0, x0+2, x0+foo); +} + diff --git a/memcheck/tests/freebsd/exterrctl.stderr.exp b/memcheck/tests/freebsd/exterrctl.stderr.exp new file mode 100644 index 000000000..59c7f2dc1 --- /dev/null +++ b/memcheck/tests/freebsd/exterrctl.stderr.exp @@ -0,0 +1,22 @@ +Syscall param exterrctl(op) contains uninitialised byte(s) + at 0x........: exterrctl (in /...libc...) + by 0x........: main (exterrctl.cpp:18) + +Syscall param exterrctl(flags) contains uninitialised byte(s) + at 0x........: exterrctl (in /...libc...) + by 0x........: main (exterrctl.cpp:18) + +Syscall param exterrctl(ptr) contains uninitialised byte(s) + at 0x........: exterrctl (in /...libc...) + by 0x........: main (exterrctl.cpp:18) + +Syscall param exterrctl(ptr) points to unaddressable byte(s) + at 0x........: exterrctl (in /...libc...) + by 0x........: main (exterrctl.cpp:18) + Address 0x........ is 0 bytes inside a block of size 176 free'd + at 0x........: ...operator delete[]... (vg_replace_malloc.c:...) + by 0x........: main (exterrctl.cpp:16) + Block was alloc'd at + at 0x........: ...operator new[]... (vg_replace_malloc.c:...) + by 0x........: main (exterrctl.cpp:15) + diff --git a/memcheck/tests/freebsd/exterrctl.vgtest b/memcheck/tests/freebsd/exterrctl.vgtest new file mode 100644 index 000000000..53d929be8 --- /dev/null +++ b/memcheck/tests/freebsd/exterrctl.vgtest @@ -0,0 +1,3 @@ +prereq: test -x ./exterrctl +prog: exterrctl +vgopts: -q -- 2.47.2