Received: from eggs.gnu.org ([2001:4830:134:3::10]:56875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIYSY-0008D8-Kk for qemu-devel@nongnu.org; Mon, 11 Jan 2016 04:08:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIYST-0006pM-Kj for qemu-devel@nongnu.org; Mon, 11 Jan 2016 04:08:18 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:59551) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIYST-0006p9-BH for qemu-devel@nongnu.org; Mon, 11 Jan 2016 04:08:13 -0500 References: <1452502446-11859-1-git-send-email-chengang@emindsoft.com.cn> From: Laurent Vivier Message-ID: <569370E8.2010009@vivier.eu> Date: Mon, 11 Jan 2016 10:07:52 +0100 MIME-Version: 1.0 In-Reply-To: <1452502446-11859-1-git-send-email-chengang@emindsoft.com.cn> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v2] linux-user/syscall.c: Add SO_RCVTIMEO and SO_SNDTIMEO for getsockopt List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: chengang@emindsoft.com.cn, riku.voipio@iki.fi Cc: peter.maydell@linaro.org, rth@twiddle.net, Chen Gang , qemu-devel@nongnu.org Le 11/01/2016 09:54, chengang@emindsoft.com.cn a écrit : > From: Chen Gang > > Implement them according to the other features implementations. > > Signed-off-by: Chen Gang > --- > linux-user/syscall.c | 27 +++++++++++++++++++++++++-- > 1 file changed, 25 insertions(+), 2 deletions(-) > > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index 44485f2..4c68800 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -1687,6 +1687,7 @@ static abi_long do_getsockopt(int sockfd, int level, int optname, > abi_long ret; > int len, val; > socklen_t lv; > + struct timeval tv; > > switch(level) { > case TARGET_SOL_SOCKET: > @@ -1694,10 +1695,32 @@ static abi_long do_getsockopt(int sockfd, int level, int optname, > switch (optname) { > /* These don't just return a single integer */ > case TARGET_SO_LINGER: > - case TARGET_SO_RCVTIMEO: > - case TARGET_SO_SNDTIMEO: > case TARGET_SO_PEERNAME: > goto unimplemented; > + case TARGET_SO_RCVTIMEO: > + optname = SO_RCVTIMEO; > + goto time_case; > + case TARGET_SO_SNDTIMEO: > + optname = SO_SNDTIMEO; > + time_case: > + if (get_user_u32(len, optlen)) { > + return -TARGET_EFAULT; > + } > + if (len < sizeof(struct target_timeval)) { > + return -TARGET_EINVAL; > + } Check len >= 0. > + lv = sizeof(tv); > + ret = get_errno(getsockopt(sockfd, level, optname, &tv, &lv)); > + if (ret < 0) { > + return ret; > + } > + if (copy_to_user_timeval(optval_addr, &tv)) { > + return -TARGET_EFAULT; > + } > + if (put_user_u32(sizeof(struct target_timeval), optlen)) { Put in optlen the result of getsockopt(), i.e. "lv", or check lv == sizeof(struct target_timeval). > + return -TARGET_EFAULT; > + } > + break; > case TARGET_SO_PEERCRED: { > struct ucred cr; > socklen_t crlen; >