qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of


From: Peter Maydell
Subject: Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup
Date: Wed, 9 May 2012 14:51:49 +0100

On 9 May 2012 14:42, Jim Meyering <address@hidden> wrote:
> From 5dce6a0222252cdc2a45ada3e3e96a8c3ef4e90f Mon Sep 17 00:00:00 2001
> From: Jim Meyering <address@hidden>
> Date: Mon, 7 May 2012 18:34:26 +0200
> Subject: [PATCH] linux-user: remove two unchecked uses of strdup
>
> Remove two uses of strdup (use g_path_get_basename instead),
> and add a comment that this strncpy use is ok.
>
> Signed-off-by: Jim Meyering <address@hidden>
> ---
>  linux-user/elfload.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index f3b1552..977283e 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -2338,13 +2338,16 @@ static int fill_psinfo(struct target_elf_prpsinfo 
> *psinfo, const TaskState *ts)
>     psinfo->pr_uid = getuid();
>     psinfo->pr_gid = getgid();
>
> -    filename = strdup(ts->bprm->filename);
> -    base_filename = strdup(basename(filename));
> +    filename = ts->bprm->filename;
> +    base_filename = g_path_get_basename(filename);

'filename' is now pointless and you might as well
just drop it and use
 base_filename = g_path_get_basename(ts->bprm->filename);

> +    /*
> +     * Using strncpy here is fine: at max-length,
> +     * this field is not NUL-terminated.
> +     */
>     (void) strncpy(psinfo->pr_fname, base_filename,
>                    sizeof(psinfo->pr_fname));
> -    free(base_filename);
> -    free(filename);
>
> +    free(base_filename);

You need to g_free() this, not free() it, right?

>     bswap_psinfo(psinfo);
>     return (0);
>  }
> --
> 1.7.10.1.487.ga3935e6


-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]