From patchwork Sun Sep 5 15:05:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blue Swirl X-Patchwork-Id: 63831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B081EB70FC for ; Mon, 6 Sep 2010 01:08:48 +1000 (EST) Received: from localhost ([127.0.0.1]:47803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OsGpp-0007Ni-Hi for incoming@patchwork.ozlabs.org; Sun, 05 Sep 2010 11:08:45 -0400 Received: from [140.186.70.92] (port=53177 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OsGmu-0006DH-Go for qemu-devel@nongnu.org; Sun, 05 Sep 2010 11:05:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OsGms-0000Gk-K8 for qemu-devel@nongnu.org; Sun, 05 Sep 2010 11:05:43 -0400 Received: from mail-qy0-f180.google.com ([209.85.216.180]:49819) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OsGms-0000Gf-Hz for qemu-devel@nongnu.org; Sun, 05 Sep 2010 11:05:42 -0400 Received: by qyk31 with SMTP id 31so3888822qyk.4 for ; Sun, 05 Sep 2010 08:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:from:date :message-id:subject:to:content-type; bh=oRzhaGw7bLVwmxs3mRldrznub9hhQroIz6A56R/K44w=; b=wcvdDb3TcwDSFQBu7gXPRMvvXLxJw5GbhF8IJoUBa2X+nmXM2HvBHXgNY0bV1HtGyc W6bjzV0EJZ1iCvHcGdVNI5hoPIVBOrW/igMq7hzuPlrA6Sxn5SWHb0/XG6xwWtFf2NI7 ajRJyNTMghG7Dv/vvEQSV+VBolzE0L922v4Qs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=sVK3+Friu+0X2mkKt5toLeYpwBTMjTlQiPhCX63VcN0YuPAKN0Emz4A+b+c6zY1cvM 5hVNr6RoLkzLRY+IfJ5kQILzZBNXSpJZmdj1bOLuRYpSQ/3PjjMAWu7WSqm/JHua77C1 y9OpS2x85QmZDwuOwgJVzSJDDG6YYkzS/y41A= Received: by 10.224.6.138 with SMTP id 10mr63885qaz.34.1283699142176; Sun, 05 Sep 2010 08:05:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.240.135 with HTTP; Sun, 5 Sep 2010 08:05:22 -0700 (PDT) From: Blue Swirl Date: Sun, 5 Sep 2010 15:05:22 +0000 Message-ID: To: qemu-devel X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 02/15] linux-user: fix socklen_t comparisons X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On many systems, socklen_t is defined as unsigned. This means that checks for negative values are not meaningful. Fix by explicitly casting to a signed integer. This also fixes some warnings with GCC flag -Wtype-limits. Signed-off-by: Blue Swirl --- linux-user/syscall.c | 20 +++++++++++++------- 1 files changed, 13 insertions(+), 7 deletions(-) @@ -1656,8 +1658,9 @@ static abi_long do_accept(int fd, abi_ulong target_addr, if (get_user_u32(addrlen, target_addrlen_addr)) return -TARGET_EINVAL; - if (addrlen < 0) + if ((int)addrlen < 0) { return -TARGET_EINVAL; + } if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) return -TARGET_EINVAL; @@ -1684,8 +1687,9 @@ static abi_long do_getpeername(int fd, abi_ulong target_addr, if (get_user_u32(addrlen, target_addrlen_addr)) return -TARGET_EFAULT; - if (addrlen < 0) + if ((int)addrlen < 0) { return -TARGET_EINVAL; + } if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) return -TARGET_EFAULT; @@ -1712,8 +1716,9 @@ static abi_long do_getsockname(int fd, abi_ulong target_addr, if (get_user_u32(addrlen, target_addrlen_addr)) return -TARGET_EFAULT; - if (addrlen < 0) + if ((int)addrlen < 0) { return -TARGET_EINVAL; + } if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) return -TARGET_EFAULT; @@ -1753,8 +1758,9 @@ static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags, void *host_msg; abi_long ret; - if (addrlen < 0) + if ((int)addrlen < 0) { return -TARGET_EINVAL; + } host_msg = lock_user(VERIFY_READ, msg, len, 1); if (!host_msg) @@ -1792,7 +1798,7 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, ret = -TARGET_EFAULT; goto fail; } - if (addrlen < 0) { + if ((int)addrlen < 0) { ret = -TARGET_EINVAL; goto fail; } diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 0ebe7e1..d44f512 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1551,8 +1551,9 @@ static abi_long do_bind(int sockfd, abi_ulong target_addr, void *addr; abi_long ret; - if (addrlen < 0) + if ((int)addrlen < 0) { return -TARGET_EINVAL; + } addr = alloca(addrlen+1); @@ -1570,8 +1571,9 @@ static abi_long do_connect(int sockfd, abi_ulong target_addr, void *addr; abi_long ret; - if (addrlen < 0) + if ((int)addrlen < 0) { return -TARGET_EINVAL; + } addr = alloca(addrlen);