[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 08/17] linux-user/syscall: Move code around in do_sendrecvmsg_
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v3 08/17] linux-user/syscall: Move code around in do_sendrecvmsg_locked() |
Date: |
Fri, 7 May 2021 16:43:06 +0200 |
Avoid initializing variables too early, since there is
2 possible failure points before they get used. Move them
after the lock_iovec() call.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
linux-user/syscall.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7c5c821f48d..593241362a9 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3379,15 +3379,8 @@ static abi_long do_sendrecvmsg_locked(int fd, struct
target_msghdr *msgp,
msg.msg_name = NULL;
msg.msg_namelen = 0;
}
- msg.msg_controllen = 2 * tswapal(msgp->msg_controllen);
- msg.msg_control = alloca(msg.msg_controllen);
- memset(msg.msg_control, 0, msg.msg_controllen);
-
- msg.msg_flags = tswap32(msgp->msg_flags);
count = tswapal(msgp->msg_iovlen);
- target_vec = tswapal(msgp->msg_iov);
-
if (count > IOV_MAX) {
/* sendrcvmsg returns a different errno for this condition than
* readv/writev, so we must catch it here before lock_iovec() does.
@@ -3396,14 +3389,20 @@ static abi_long do_sendrecvmsg_locked(int fd, struct
target_msghdr *msgp,
goto out2;
}
+ target_vec = tswapal(msgp->msg_iov);
vec = lock_iovec(send ? VERIFY_READ : VERIFY_WRITE,
target_vec, count, send);
if (vec == NULL) {
ret = -host_to_target_errno(errno);
goto out2;
}
+
msg.msg_iovlen = count;
msg.msg_iov = vec;
+ msg.msg_flags = tswap32(msgp->msg_flags);
+ msg.msg_controllen = 2 * tswapal(msgp->msg_controllen);
+ msg.msg_control = alloca(msg.msg_controllen);
+ memset(msg.msg_control, 0, msg.msg_controllen);
if (send) {
if (fd_trans_target_to_host_data(fd)) {
--
2.26.3
- [PATCH v3 00/17] misc: Replace alloca() by g_malloc(), Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 01/17] bsd-user/syscall: Replace alloca() by g_try_new(), Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 02/17] linux-user/elfload: Replace alloca() by g_try_malloc(), Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 03/17] linux-user/syscall: Replace alloca() by g_try_new(), Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 04/17] linux-user/syscall: Replace alloca() by g_try_malloc(), Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 05/17] linux-user: Replace alloca() by g_try_new() in ppoll() syscall, Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 06/17] linux-user: Replace alloca() by g_try_malloc() in setsockopt() syscall, Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 07/17] linux-user: Replace alloca() by g_try_malloc() in various socket syscall, Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 08/17] linux-user/syscall: Move code around in do_sendrecvmsg_locked(),
Philippe Mathieu-Daudé <=
- [PATCH v3 11/17] backends/tpm: Replace g_alloca() by g_malloc(), Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 10/17] audio/alsaaudio: Replace ALSA alloca() by malloc() equivalent, Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 12/17] gdbstub: Constify GdbCmdParseEntry, Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 09/17] linux-user/syscall: Replace alloca() by GLib alloc() in sendrecvmsg, Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 13/17] gdbstub: Replace GdbCmdContext with plain g_array(), Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 14/17] hw/misc/pca9552: Replace g_newa() by g_new(), Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 15/17] target/ppc/kvm: Replace alloca() by g_malloc(), Philippe Mathieu-Daudé, 2021/05/07
- [PATCH v3 16/17] configure: Prohibit alloca() by using -Walloca CPPFLAG, Philippe Mathieu-Daudé, 2021/05/07