|
From: Paul F. <pa...@so...> - 2025-11-09 08:31:20
|
https://sourceware.org/cgit/valgrind/commit/?id=f1ae846a7feeb4f48f904dd074f490cd96ad1e1b commit f1ae846a7feeb4f48f904dd074f490cd96ad1e1b Author: Paul Floyd <pj...@wa...> Date: Sun Nov 9 09:29:17 2025 +0100 FreeBSD regtest: getsockopt and setsockopt scalar tests were wrong getsockopt was miscopied as setsockopt and the memory checks weere not good. Diff: --- coregrind/m_syswrap/syswrap-freebsd.c | 2 +- memcheck/tests/freebsd/scalar.c | 17 ++++++++++++---- memcheck/tests/freebsd/scalar.stderr.exp | 29 +++++++++++++++++++++------- memcheck/tests/freebsd/scalar.stderr.exp-x86 | 29 +++++++++++++++++++++------- 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/coregrind/m_syswrap/syswrap-freebsd.c b/coregrind/m_syswrap/syswrap-freebsd.c index dce26ba915..c2fd35d2b1 100644 --- a/coregrind/m_syswrap/syswrap-freebsd.c +++ b/coregrind/m_syswrap/syswrap-freebsd.c @@ -1510,7 +1510,7 @@ PRE(sys_getsockopt) PRINT("sys_getsockopt ( %" FMT_REGWORD "u, %" FMT_REGWORD "u, %" FMT_REGWORD "u, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )",ARG1,ARG2,ARG3,ARG4,ARG5); PRE_REG_READ5(int, "getsockopt", int, s, int, level, int, optname, - void *, optval, int, *optlen); + void *, optval, vki_socklen_t, *optlen); if (optval_p != (Addr)NULL) { ML_(buf_and_len_pre_check) ( tid, optval_p, optlen_p, "getsockopt(optval)", diff --git a/memcheck/tests/freebsd/scalar.c b/memcheck/tests/freebsd/scalar.c index acb4b662e7..b4d7a46d13 100644 --- a/memcheck/tests/freebsd/scalar.c +++ b/memcheck/tests/freebsd/scalar.c @@ -449,8 +449,8 @@ int main(void) SY(SYS_bind, x0, x0, x0); FAIL; /* SYS_setsockopt 105 */ - GO(SYS_setsockopt, "5s 0m"); - SY(SYS_setsockopt, x0, x0, x0, x0, x0); FAIL; + GO(SYS_setsockopt, "5s 1m"); + SY(SYS_setsockopt, x0, x0, x0, px+x0, sizeof(socklen_t)+x0); FAIL; /* SYS_listen 106 */ GO(SYS_listen, "2s 0m"); @@ -482,9 +482,18 @@ int main(void) GO(SYS_getrusage, "2s 1m"); SY(SYS_getrusage, x0, x0); FAIL; + socklen_t *len = malloc(sizeof(socklen_t)); + *len = 2*sizeof(long)+x0; + free(len); + /* + * Should be 2m but it is hard to trigger an optval + * error in the scalar, len needs to be safe to deref + * and the syscall needs to succeed to trigger a write + * error to optval + */ /* SYS_getsockopt 118 */ - GO(SYS_setsockopt, "5s 1m"); - SY(SYS_setsockopt, x0, x0, x0, x0, x0); FAIL; + GO(SYS_getsockopt, "5s 1m"); + SY(SYS_getsockopt, x0, x0, x0, px+x0, len+x0); FAIL; /* unimpl resuba 119 */ diff --git a/memcheck/tests/freebsd/scalar.stderr.exp b/memcheck/tests/freebsd/scalar.stderr.exp index 2acb864e73..449075f3e0 100644 --- a/memcheck/tests/freebsd/scalar.stderr.exp +++ b/memcheck/tests/freebsd/scalar.stderr.exp @@ -856,7 +856,7 @@ Syscall param bind(addrlen) contains uninitialised byte(s) ... --------------------------------------------------------- -105: SYS_setsockopt 5s 0m +105: SYS_setsockopt 5s 1m --------------------------------------------------------- Syscall param setsockopt(s) contains uninitialised byte(s) ... @@ -873,6 +873,12 @@ Syscall param setsockopt(optval) contains uninitialised byte(s) Syscall param setsockopt(optlen) contains uninitialised byte(s) ... +Syscall param socketcall.setsockopt(optval) points to uninitialised byte(s) + ... + Address 0x........ is 0 bytes inside a block of size 16 alloc'd + at 0x........: malloc (vg_replace_malloc.c:...) + ... + --------------------------------------------------------- 106: SYS_listen 2s 0m --------------------------------------------------------- @@ -913,21 +919,30 @@ Syscall param getrusage(usage) points to unaddressable byte(s) Address 0x........ is not stack'd, malloc'd or (recently) free'd --------------------------------------------------------- -105: SYS_setsockopt 5s 1m +118: SYS_getsockopt 5s 1m --------------------------------------------------------- -Syscall param setsockopt(s) contains uninitialised byte(s) +Syscall param getsockopt(s) contains uninitialised byte(s) ... -Syscall param setsockopt(level) contains uninitialised byte(s) +Syscall param getsockopt(level) contains uninitialised byte(s) ... -Syscall param setsockopt(optname) contains uninitialised byte(s) +Syscall param getsockopt(optname) contains uninitialised byte(s) ... -Syscall param setsockopt(optval) contains uninitialised byte(s) +Syscall param getsockopt(optval) contains uninitialised byte(s) ... -Syscall param setsockopt(optlen) contains uninitialised byte(s) +Syscall param getsockopt(*optlen) contains uninitialised byte(s) + ... + +Syscall param getsockopt(optlen) points to unaddressable byte(s) + ... + Address 0x........ is 0 bytes inside a block of size 4 free'd + at 0x........: free (vg_replace_malloc.c:...) + ... + Block was alloc'd at + at 0x........: malloc (vg_replace_malloc.c:...) ... --------------------------------------------------------- diff --git a/memcheck/tests/freebsd/scalar.stderr.exp-x86 b/memcheck/tests/freebsd/scalar.stderr.exp-x86 index 957ffb2058..e7e2ce0a6b 100644 --- a/memcheck/tests/freebsd/scalar.stderr.exp-x86 +++ b/memcheck/tests/freebsd/scalar.stderr.exp-x86 @@ -856,7 +856,7 @@ Syscall param bind(addrlen) contains uninitialised byte(s) ... --------------------------------------------------------- -105: SYS_setsockopt 5s 0m +105: SYS_setsockopt 5s 1m --------------------------------------------------------- Syscall param setsockopt(s) contains uninitialised byte(s) ... @@ -873,6 +873,12 @@ Syscall param setsockopt(optval) contains uninitialised byte(s) Syscall param setsockopt(optlen) contains uninitialised byte(s) ... +Syscall param socketcall.setsockopt(optval) points to uninitialised byte(s) + ... + Address 0x........ is 0 bytes inside a block of size 16 alloc'd + at 0x........: malloc (vg_replace_malloc.c:...) + ... + --------------------------------------------------------- 106: SYS_listen 2s 0m --------------------------------------------------------- @@ -913,21 +919,30 @@ Syscall param getrusage(usage) points to unaddressable byte(s) Address 0x........ is not stack'd, malloc'd or (recently) free'd --------------------------------------------------------- -105: SYS_setsockopt 5s 1m +118: SYS_getsockopt 5s 1m --------------------------------------------------------- -Syscall param setsockopt(s) contains uninitialised byte(s) +Syscall param getsockopt(s) contains uninitialised byte(s) ... -Syscall param setsockopt(level) contains uninitialised byte(s) +Syscall param getsockopt(level) contains uninitialised byte(s) ... -Syscall param setsockopt(optname) contains uninitialised byte(s) +Syscall param getsockopt(optname) contains uninitialised byte(s) ... -Syscall param setsockopt(optval) contains uninitialised byte(s) +Syscall param getsockopt(optval) contains uninitialised byte(s) ... -Syscall param setsockopt(optlen) contains uninitialised byte(s) +Syscall param getsockopt(*optlen) contains uninitialised byte(s) + ... + +Syscall param getsockopt(optlen) points to unaddressable byte(s) + ... + Address 0x........ is 0 bytes inside a block of size 4 free'd + at 0x........: free (vg_replace_malloc.c:...) + ... + Block was alloc'd at + at 0x........: malloc (vg_replace_malloc.c:...) ... --------------------------------------------------------- |