From patchwork Mon Apr 13 21:25:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 460950 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 931BD140281 for ; Tue, 14 Apr 2015 07:26:01 +1000 (AEST) Received: from localhost ([::1]:53481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yhlri-0005pj-7g for incoming@patchwork.ozlabs.org; Mon, 13 Apr 2015 17:25:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yhlr7-0002mq-Ne for qemu-devel@nongnu.org; Mon, 13 Apr 2015 17:25:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yhlr6-00079G-Jp for qemu-devel@nongnu.org; Mon, 13 Apr 2015 17:25:21 -0400 Received: from smtp5-g21.free.fr ([2a01:e0c:1:1599::14]:54069) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yhlr6-00079A-EZ for qemu-devel@nongnu.org; Mon, 13 Apr 2015 17:25:20 -0400 Received: from Quad (unknown [IPv6:2a01:e34:eeee:5240:7c6a:24fb:2844:b583]) by smtp5-g21.free.fr (Postfix) with ESMTPS id 43E47D4802A; Mon, 13 Apr 2015 23:22:51 +0200 (CEST) Received: from laurent by Quad with local (Exim 4.82) (envelope-from ) id 1Yhlqz-0003fD-QD; Mon, 13 Apr 2015 23:25:13 +0200 From: Laurent Vivier To: Riku Voipio Date: Mon, 13 Apr 2015 23:25:02 +0200 Message-Id: <1428960302-14046-1-git-send-email-laurent@vivier.eu> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:e0c:1:1599::14 Cc: qemu-devel@nongnu.org, Laurent Vivier Subject: [Qemu-devel] [PATCH] linux-user: in poll(), if nfds is 0, pfd can be NULL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This problem appears with yum in Fedora 20 / PPC64 container. test case: #include #include int main(void) { int ret; ret = poll(NULL, 0, 1000); printf("%d\n", ret); } target test environment: Fedora 20 / PPC64 host test environment: Ubuntu 14.0.2 / x86_64 original test result: -1 13451 poll(0,0,1000,274886297496,268566664,268566648) = -1 errno=14 (Bad address) patched test result: 0 13536 poll(0,0,1000,274886297496,268566664,268566648) = 0 Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1622ad6..d61a349 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7694,14 +7694,20 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, struct pollfd *pfd; unsigned int i; - target_pfd = lock_user(VERIFY_WRITE, arg1, sizeof(struct target_pollfd) * nfds, 1); - if (!target_pfd) - goto efault; + pfd = NULL; + target_pfd = NULL; + if (nfds) { + target_pfd = lock_user(VERIFY_WRITE, arg1, + sizeof(struct target_pollfd) * nfds, 1); + if (!target_pfd) { + goto efault; + } - pfd = alloca(sizeof(struct pollfd) * nfds); - for(i = 0; i < nfds; i++) { - pfd[i].fd = tswap32(target_pfd[i].fd); - pfd[i].events = tswap16(target_pfd[i].events); + pfd = alloca(sizeof(struct pollfd) * nfds); + for (i = 0; i < nfds; i++) { + pfd[i].fd = tswap32(target_pfd[i].fd); + pfd[i].events = tswap16(target_pfd[i].events); + } } # ifdef TARGET_NR_ppoll