qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: zhuoweizhang@yahoo.com, qemu-devel@nongnu.org
Cc: riku.voipio@iki.fi
Subject: Re: [Qemu-devel] [PATCH v2] syscall: fix special case of write(fd, NULL, 0)
Date: Sat, 30 Sep 2017 17:28:06 +0200	[thread overview]
Message-ID: <1ae4e3b7-e3d0-e58b-ca11-db5ba8e0f438@vivier.eu> (raw)
In-Reply-To: <1506784985-4107-1-git-send-email-zhuoweizhang@yahoo.com>

Le 30/09/2017 à 17:23, zhuoweizhang@yahoo.com a écrit :
> From: Zhuowei Zhang <zhuoweizhang@yahoo.com>
> 
> Linux returns success for the special case of calling write with a zero-length
> NULL buffer: compiling and running
> 
> ```
> #include <stdio.h>
> #include <unistd.h>
> #include <fcntl.h>
> 
> int main() {
>    ssize_t ret = write(STDOUT_FILENO, NULL, 0);
>    fprintf(stderr, "write returned %ld\n", ret);
>    return 0;
> }
> ```
> gives "write returned 0" when run directly, but "write returned -1" in QEMU.
> 
> This commit checks for this situation and calls the real syscall with a NULL
> buffer and zero length, which gives the correct return value.
> 
> Signed-off-by: Zhuowei Zhang <zhuoweizhang@yahoo.com>
> ---
>  linux-user/syscall.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 9b6364a..60769c0 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -7783,6 +7783,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>          }
>          break;
>      case TARGET_NR_write:
> +        if (arg2 == 0 && arg3 == 0) {
> +            /* special case: write(fd, NULL, 0) returns success. */
> +            ret = get_errno(safe_write(arg1, NULL, 0));
> +            break;
> +        }
>          if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
>              goto efault;
>          if (fd_trans_target_to_host_data(arg1)) {
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>

Could you change the NR_read too, for consistency?

Thanks,
Laurent

  reply	other threads:[~2017-09-30 15:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-30 15:23 [Qemu-devel] [PATCH v2] syscall: fix special case of write(fd, NULL, 0) zhuoweizhang
2017-09-30 15:28 ` Laurent Vivier [this message]
2017-09-30 23:12 ` Carlo Arenas
2017-10-02  1:09   ` Carlo Arenas
     [not found] <2080649258.295593.1506786541765.ref@mail.yahoo.com>
2017-09-30 15:49 ` Zhuowei zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1ae4e3b7-e3d0-e58b-ca11-db5ba8e0f438@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    --cc=zhuoweizhang@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).