[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 03/17] linux-user: in poll(), if nfds is 0, pfd can b
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PULL 03/17] linux-user: in poll(), if nfds is 0, pfd can be NULL |
Date: |
Mon, 11 Jan 2016 16:16:05 +0200 |
From: Laurent Vivier <address@hidden>
This problem appears with yum in Fedora 20 / PPC64 container.
test case:
#include <stdio.h>
#include <poll.h>
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 <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
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 8fa8e0c..c216966 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8046,14 +8046,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
--
2.6.4
- [Qemu-devel] [PULL 00/17] linux-user queque, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 01/17] linux-user: add signalfd/signalfd4 syscalls, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 06/17] linux-user: rename TargetFdFunc to TargetFdDataFunc, and structure fields accordingly, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 04/17] linux-user/syscall.c: malloc()/calloc() to g_malloc()/g_try_malloc()/g_new0(), riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 05/17] linux-user: SOCK_PACKET uses network endian to encode protocol in socket(), riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 03/17] linux-user: in poll(), if nfds is 0, pfd can be NULL,
riku . voipio <=
- [Qemu-devel] [PULL 02/17] linux-user: correctly align target_epoll_event, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 08/17] linux-user: manage bind with a socket of SOCK_PACKET type., riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 17/17] linux-user/mmap.c: Use end instead of real_end in target_mmap, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 11/17] linux-user/mmap.c: Always zero MAP_ANONYMOUS memory in mmap_frag(), riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 07/17] linux-user: add a function hook to translate sockaddr, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 14/17] linux-user/syscall.c: Use SOL_SOCKET instead of level for setsockopt(), riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 15/17] linux-user: Update m68k syscall definitions to match Linux 4.4., riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 10/17] linux-user, sh4: fix signal retcode address, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 09/17] linux-user: check fd is >= 0 in fd_trans_host_to_target_data/fd_trans_host_to_target_addr, riku . voipio, 2016/01/11
- [Qemu-devel] [PULL 13/17] linux-user: enable sigaltstack for all architectures, riku . voipio, 2016/01/11