aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daudé <f4bug@amsat.org>2017-07-26 23:42:19 -0300
committerMichael Tokarev <mjt@tls.msk.ru>2017-07-31 13:06:39 +0300
commitb929f7e56f505d18bea32b08b57a8b84c6b28f30 (patch)
tree118c00d4263a29375d42bb35e36b7004ec660b9c
parent6860710cc3864382a898c847d722f950b5e01a6e (diff)
downloadqemu-b929f7e56f505d18bea32b08b57a8b84c6b28f30.zip
qemu-b929f7e56f505d18bea32b08b57a8b84c6b28f30.tar.gz
qemu-b929f7e56f505d18bea32b08b57a8b84c6b28f30.tar.bz2
syscall: check inotify() and eventfd() return value
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>
-rw-r--r--linux-user/syscall.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 81f52f7..dfc1301 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