[Top][All Lists]
[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:29:15 +0100 |
On 9 May 2012 10:23, Jim Meyering <address@hidden> wrote:
> From: Jim Meyering <address@hidden>
>
> Remove unnecessary and unchecked uses of strdup,
> and add a comment that this strncpy use is ok.
>
> Signed-off-by: Jim Meyering <address@hidden>
> ---
> linux-user/elfload.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index f3b1552..25175cc 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -2338,12 +2338,14 @@ 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 = basename(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);
This doesn't look right -- basename can modify
the string it's passed, which is why we create a copy
for it.
-- PMM
- [Qemu-devel] [PATCH 07/22] ppc: avoid buffer overrun: use pstrcpy, not strncpy, (continued)
- [Qemu-devel] [PATCH 07/22] ppc: avoid buffer overrun: use pstrcpy, not strncpy, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 02/22] sheepdog: avoid a few buffer overruns, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 14/22] vscsi: avoid unwarranted strncpy, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 20/22] hw/r2d: add comment: this strncpy use is ok, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 04/22] hw/9pfs: avoid buffer overrun, Jim Meyering, 2012/05/09
- [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Jim Meyering, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup,
Peter Maydell <=
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Jim Meyering, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Peter Maydell, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Jim Meyering, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Peter Maydell, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Jim Meyering, 2012/05/09
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Anthony Liguori, 2012/05/30
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Jim Meyering, 2012/05/30
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Anthony Liguori, 2012/05/30
- Re: [Qemu-devel] [PATCH 08/22] linux-user: remove two unchecked uses of strdup, Jim Meyering, 2012/05/30
[Qemu-devel] [PATCH 03/22] vmdk: relative_path: avoid buffer overrun, Jim Meyering, 2012/05/09