[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 04/17] linux-user/syscall: Replace alloca() by g_try_malloc()
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v3 04/17] linux-user/syscall: Replace alloca() by g_try_malloc() |
Date: |
Fri, 7 May 2021 16:43:02 +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 | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 08ab4cee805..2fa6b89b3de 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -10630,7 +10630,7 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
case TARGET_NR_sched_getaffinity:
{
unsigned int mask_size;
- unsigned long *mask;
+ g_autofree unsigned long *mask = NULL;
/*
* sched_getaffinity needs multiples of ulong, so need to take
@@ -10641,8 +10641,10 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
}
mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);
- mask = alloca(mask_size);
- memset(mask, 0, mask_size);
+ mask = g_try_malloc0(mask_size);
+ if (!mask) {
+ return -TARGET_ENOMEM;
+ }
ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask));
if (!is_error(ret)) {
@@ -10670,7 +10672,7 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
case TARGET_NR_sched_setaffinity:
{
unsigned int mask_size;
- unsigned long *mask;
+ g_autofree unsigned long *mask = NULL;
/*
* sched_setaffinity needs multiples of ulong, so need to take
@@ -10680,7 +10682,10 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
return -TARGET_EINVAL;
}
mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1);
- mask = alloca(mask_size);
+ mask = g_try_malloc(mask_size);
+ if (!mask) {
+ return -TARGET_ENOMEM;
+ }
ret = target_to_host_cpu_mask(mask, mask_size, arg3, arg2);
if (ret) {
--
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é <=
- [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 08/17] linux-user/syscall: Move code around in do_sendrecvmsg_locked(), 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 09/17] linux-user/syscall: Replace alloca() by GLib alloc() in sendrecvmsg, 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 14/17] hw/misc/pca9552: Replace g_newa() by g_new(), 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 13/17] gdbstub: Replace GdbCmdContext with plain g_array(), Philippe Mathieu-Daudé, 2021/05/07