[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 2/2] linux-user: allocate heap memory for exe
From: |
Peter Maydell |
Subject: |
Re: [Qemu-devel] [PATCH v2 2/2] linux-user: allocate heap memory for execve arguments |
Date: |
Mon, 6 Mar 2017 15:57:36 +0000 |
On 6 March 2017 at 07:17, P J P <address@hidden> wrote:
> From: Prasad J Pandit <address@hidden>
>
> Arguments passed to execve(2) call from user program could
> be large, allocating stack memory for them via alloca(3) call
> would lead to bad behaviour. Use 'g_malloc0' to allocate memory
> for such arguments.
>
> Signed-off-by: Prasad J Pandit <address@hidden>
> ---
> linux-user/syscall.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> Update per: replace alloca() with g_malloc0()
> -> https://lists.gnu.org/archive/html/qemu-devel/2017-03/msg00750.html
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 86a4a9c..404fb0b 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -7800,8 +7800,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long
> arg1,
> ret = -TARGET_E2BIG;
> break;
> }
> - argp = alloca((argc + 1) * sizeof(void *));
> - envp = alloca((envc + 1) * sizeof(void *));
> + argp = g_malloc0((argc + 1) * sizeof(void *));
> + envp = g_malloc0((envc + 1) * sizeof(void *));
>
> for (gp = guest_argp, q = argp; gp;
> gp += sizeof(abi_ulong), q++) {
> @@ -7862,6 +7862,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long
> arg1,
> break;
> unlock_user(*q, addr, 0);
> }
> +
> + g_free(argp);
> + g_free(envp);
> }
> break;
> case TARGET_NR_chdir:
Better to use the _try_ glib allocation functions and fail
the syscall on allocation failure, maybe?
thanks
-- PMM