From: Florian Krohm Date: Sat, 25 Apr 2015 18:14:17 +0000 (+0000) Subject: Fix the writev / readv wrappers. Do not read the array pointed to X-Git-Tag: svn/VALGRIND_3_11_0~456 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e0927ca1ea7223b1d6db155b4ed8821e05e38d59;p=thirdparty%2Fvalgrind.git Fix the writev / readv wrappers. Do not read the array pointed to by the 2nd argument, if the element count is negative. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15143 --- diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index cb3cfb1aac..2fd37d1cbe 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -4006,7 +4006,8 @@ PRE(sys_readv) if (!ML_(fd_allowed)(ARG1, "readv", tid, False)) { SET_STATUS_Failure( VKI_EBADF ); } else { - PRE_MEM_READ( "readv(vector)", ARG2, ARG3 * sizeof(struct vki_iovec) ); + if ((Int)ARG3 >= 0) + PRE_MEM_READ( "readv(vector)", ARG2, ARG3 * sizeof(struct vki_iovec) ); if (ARG2 != 0) { /* ToDo: don't do any of the following if the vector is invalid */ @@ -4335,8 +4336,9 @@ PRE(sys_writev) if (!ML_(fd_allowed)(ARG1, "writev", tid, False)) { SET_STATUS_Failure( VKI_EBADF ); } else { - PRE_MEM_READ( "writev(vector)", - ARG2, ARG3 * sizeof(struct vki_iovec) ); + if ((Int)ARG3 >= 0) + PRE_MEM_READ( "writev(vector)", + ARG2, ARG3 * sizeof(struct vki_iovec) ); if (ARG2 != 0) { /* ToDo: don't do any of the following if the vector is invalid */ vec = (struct vki_iovec *)ARG2; diff --git a/memcheck/tests/writev1.c b/memcheck/tests/writev1.c index 82ad47f9ba..6a8c281c89 100644 --- a/memcheck/tests/writev1.c +++ b/memcheck/tests/writev1.c @@ -80,7 +80,7 @@ int main(void) fprintf(stderr, "expected errno = EINVAL, got %d\n", errno); } else - fprintf(stderr, "Error writev returned a positive value\n"); + fprintf(stderr, "Error readv returned a positive value\n"); unlink(f_name); diff --git a/memcheck/tests/writev1.stderr.exp b/memcheck/tests/writev1.stderr.exp index 6063a3805f..0fe62eecb7 100644 --- a/memcheck/tests/writev1.stderr.exp +++ b/memcheck/tests/writev1.stderr.exp @@ -5,15 +5,5 @@ Syscall param writev(vector[...]) points to unaddressable byte(s) Address 0x........ is not stack'd, malloc'd or (recently) free'd Received EFAULT as expected -Syscall param writev(vector) points to unaddressable byte(s) - ... - by 0x........: main (writev1.c:68) - Address 0x........ is not stack'd, malloc'd or (recently) free'd - Received EINVAL as expected -Syscall param readv(vector) points to unaddressable byte(s) - ... - by 0x........: main (writev1.c:76) - Address 0x........ is not stack'd, malloc'd or (recently) free'd - Received EINVAL as expected