qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	qemu-trivial@nongnu.org, "Michael Tokarev" <mjt@tls.msk.ru>
Subject: [Qemu-devel] [PULL 17/25] syscall: check inotify() and eventfd() return value
Date: Mon, 31 Jul 2017 13:21:36 +0300	[thread overview]
Message-ID: <b929f7e56f505d18bea32b08b57a8b84c6b28f30.1501496350.git.mjt@msgid.tls.msk.ru> (raw)
In-Reply-To: <cover.1501496349.git.mjt@msgid.tls.msk.ru>
In-Reply-To: <cover.1501496349.git.mjt@msgid.tls.msk.ru>

From: Philippe Mathieu-Daudé <f4bug@amsat.org>

linux-user/syscall.c:555:25: warning: Out of bound memory access (accessed memory precedes memory block)
    target_fd_trans[fd] = trans;
    ~~~~~~~~~~~~~~~~~~~~^~~~~~~

Reported-by: Clang Static Analyzer
Suggested-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 linux-user/syscall.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 81f52f7483..dfc1301e63 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11742,7 +11742,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
     case TARGET_NR_inotify_init:
         ret = get_errno(sys_inotify_init());
-        fd_trans_register(ret, &target_inotify_trans);
+        if (ret >= 0) {
+            fd_trans_register(ret, &target_inotify_trans);
+        }
         break;
 #endif
 #ifdef CONFIG_INOTIFY1
@@ -11750,7 +11752,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_inotify_init1:
         ret = get_errno(sys_inotify_init1(target_to_host_bitmask(arg1,
                                           fcntl_flags_tbl)));
-        fd_trans_register(ret, &target_inotify_trans);
+        if (ret >= 0) {
+            fd_trans_register(ret, &target_inotify_trans);
+        }
         break;
 #endif
 #endif
@@ -11916,7 +11920,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #if defined(TARGET_NR_eventfd)
     case TARGET_NR_eventfd:
         ret = get_errno(eventfd(arg1, 0));
-        fd_trans_register(ret, &target_eventfd_trans);
+        if (ret >= 0) {
+            fd_trans_register(ret, &target_eventfd_trans);
+        }
         break;
 #endif
 #if defined(TARGET_NR_eventfd2)
@@ -11930,7 +11936,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             host_flags |= O_CLOEXEC;
         }
         ret = get_errno(eventfd(arg1, host_flags));
-        fd_trans_register(ret, &target_eventfd_trans);
+        if (ret >= 0) {
+            fd_trans_register(ret, &target_eventfd_trans);
+        }
         break;
     }
 #endif
-- 
2.11.0

  parent reply	other threads:[~2017-07-31 10:32 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-31 10:21 [Qemu-devel] [PULL 00/25 for-2.10] Trivial patches for 2017-07-31 Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 01/25] tests: check-qom-proplist: fix leak Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 02/25] fix qemu-system-unicore32 crashing when calling without -kernel Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 03/25] MAINTAINERS: Improve the NetBSD regex pattern Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 04/25] tests: test-netfilter && pxe-test require slirp Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 05/25] build-sys: there is no qemu-ga.c Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 06/25] qemu-system-tricore: segfault when entering "x 0" on the monitor Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 07/25] tests: add missing dependency to build QTEST_QEMU_BINARY Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 08/25] loader: check get_image_size() return value Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 09/25] ivshmem: fix incorrect error handling in ivshmem_recv_msg() Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 10/25] qcow2: fix null pointer dereference Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 11/25] ui/vnc: fix leak of SocketAddress ** Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 12/25] net/eth: fix incorrect check of iov_to_buf() return value Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 13/25] m68k/translate: fix incorrect copy/paste Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 14/25] linux-user/sh4: fix incorrect memory write Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 15/25] syscall: fix dereference of undefined pointer Michael Tokarev
2017-07-31 13:01   ` Peter Maydell
2017-07-31 10:21 ` [Qemu-devel] [PULL 16/25] syscall: fix use of uninitialized values Michael Tokarev
2017-07-31 10:21 ` Michael Tokarev [this message]
2017-07-31 10:21 ` [Qemu-devel] [PULL 18/25] thunk: assert nb_fields is valid Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 19/25] docs: fix broken paths to docs/interop dir Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 20/25] docs: fix broken paths to docs/interop/qcow2.txt Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 21/25] docs: fix broken paths to docs/devel/qapi-code-gen.txt Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 22/25] docs: fix broken paths to docs/devel/atomics.txt Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 23/25] docs: fix broken paths to docs/devel/tracing.txt Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 24/25] docs: fix broken paths to docs/config/ich9-ehci-uhci.cfg Michael Tokarev
2017-07-31 10:21 ` [Qemu-devel] [PULL 25/25] docs: fix broken paths to docs/specs/ivshmem-spec.txt Michael Tokarev
2017-07-31 12:01 ` [Qemu-devel] [PULL 00/25 for-2.10] Trivial patches for 2017-07-31 Peter Maydell

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=b929f7e56f505d18bea32b08b57a8b84c6b28f30.1501496350.git.mjt@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=f4bug@amsat.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /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).