[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 05/17] linux-user: Replace alloca() by g_try_new() in ppoll()
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v3 05/17] linux-user: Replace alloca() by g_try_new() in ppoll() syscall |
Date: |
Fri, 7 May 2021 16:43:03 +0200 |
The ALLOCA(3) man-page mentions its "use is discouraged".
Use autofree heap allocation instead (returning ENOMEM on failure).
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
linux-user/syscall.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2fa6b89b3de..0bf4273fc7a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1605,11 +1605,10 @@ static abi_long do_ppoll(abi_long arg1, abi_long arg2,
abi_long arg3,
{
struct target_pollfd *target_pfd;
unsigned int nfds = arg2;
- struct pollfd *pfd;
+ g_autofree struct pollfd *pfd = NULL;
unsigned int i;
abi_long ret;
- pfd = NULL;
target_pfd = NULL;
if (nfds) {
if (nfds > (INT_MAX / sizeof(struct target_pollfd))) {
@@ -1621,7 +1620,10 @@ static abi_long do_ppoll(abi_long arg1, abi_long arg2,
abi_long arg3,
return -TARGET_EFAULT;
}
- pfd = alloca(sizeof(struct pollfd) * nfds);
+ pfd = g_try_new(struct pollfd, nfds);
+ if (!pfd) {
+ return -TARGET_ENOMEM;
+ }
for (i = 0; i < nfds; i++) {
pfd[i].fd = tswap32(target_pfd[i].fd);
pfd[i].events = tswap16(target_pfd[i].events);
--
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é <=
- [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é, 2021/05/07
- [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