QEMU Linux usermode emulation does not handle write() syscalls with zero length and a null pointer correctly: on Linux this returns 0, but in emulation this returns -1.
I ran into this while using an aarch64 abuild-tar from Alpine Linux in user-mode emulation; here's the minimized reproduction test case:
QEMU version: latest master (fcea73709b966a 7ded9efa7b106ea 50c7fe9025c) list=x86_ 64-linux- user
OS version: Ubuntu 14.04.3
Configured with: ../configure --target-
QEMU Linux usermode emulation does not handle write() syscalls with zero length and a null pointer correctly: on Linux this returns 0, but in emulation this returns -1.
I ran into this while using an aarch64 abuild-tar from Alpine Linux in user-mode emulation; here's the minimized reproduction test case:
zhuowei@ zhuowei- tablet: /tmp$ cat writezerobytes.c
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main() { FILENO, NULL, 0); zhuowei- tablet: /tmp$ gcc -o writezerobytes writezerobytes.c zhuowei- tablet: /tmp$ uname -a zhuowei- tablet: /tmp$ ./writezerobytes zhuowei- tablet: /tmp$ /media/ zhuowei/ redhd/docs/ repos/qemu/ build4/ x86_64- linux-user/ qemu-x86_ 64 ./writezerobytes zhuowei- tablet: /tmp$ /media/ zhuowei/ redhd/docs/ repos/qemu/ build4/ x86_64- linux-user/ qemu-x86_ 64 --version 0-471-gfcea737- dirty)
ssize_t ret = write(STDOUT_
fprintf(stderr, "write returned %ld\n", ret);
return 0;
}
zhuowei@
zhuowei@
Linux zhuowei-tablet 3.13.0-129-generic #178-Ubuntu SMP Fri Aug 11 12:48:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
zhuowei@
write returned 0
zhuowei@
write returned -1
zhuowei@
qemu-x86_64 version 2.10.50 (v2.10.
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers