[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 03/17] linux-user/syscall: Replace alloca() by g_try_new()
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v3 03/17] linux-user/syscall: Replace alloca() by g_try_new() |
Date: |
Fri, 7 May 2021 16:43:01 +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 | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 95d79ddc437..08ab4cee805 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11417,10 +11417,12 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
{
int gidsetsize = arg1;
target_id *target_grouplist;
- gid_t *grouplist;
+ g_autofree gid_t *grouplist = g_try_new(gid_t, gidsetsize);
int i;
- grouplist = alloca(gidsetsize * sizeof(gid_t));
+ if (!grouplist) {
+ return -TARGET_ENOMEM;
+ }
ret = get_errno(getgroups(gidsetsize, grouplist));
if (gidsetsize == 0)
return ret;
@@ -11438,10 +11440,13 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
{
int gidsetsize = arg1;
target_id *target_grouplist;
- gid_t *grouplist = NULL;
+ g_autofree gid_t *grouplist = NULL;
int i;
if (gidsetsize) {
- grouplist = alloca(gidsetsize * sizeof(gid_t));
+ grouplist = g_try_new(gid_t, gidsetsize);
+ if (!grouplist) {
+ return -TARGET_ENOMEM;
+ }
target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize *
sizeof(target_id), 1);
if (!target_grouplist) {
return -TARGET_EFAULT;
@@ -11736,10 +11741,12 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
{
int gidsetsize = arg1;
uint32_t *target_grouplist;
- gid_t *grouplist;
+ g_autofree gid_t *grouplist = g_try_new(gid_t, gidsetsize);
int i;
- grouplist = alloca(gidsetsize * sizeof(gid_t));
+ if (!grouplist) {
+ return -TARGET_ENOMEM;
+ }
ret = get_errno(getgroups(gidsetsize, grouplist));
if (gidsetsize == 0)
return ret;
@@ -11760,10 +11767,12 @@ static abi_long do_syscall1(void *cpu_env, int num,
abi_long arg1,
{
int gidsetsize = arg1;
uint32_t *target_grouplist;
- gid_t *grouplist;
+ g_autofree gid_t *grouplist = g_try_new(gid_t, gidsetsize);
int i;
- grouplist = alloca(gidsetsize * sizeof(gid_t));
+ if (!grouplist) {
+ return -TARGET_ENOMEM;
+ }
target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 4, 1);
if (!target_grouplist) {
return -TARGET_EFAULT;
--
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é <=
- [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 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