qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [RFC v2 1/4] elf: Add optional function ptr to load_elf


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [RFC v2 1/4] elf: Add optional function ptr to load_elf() to parse ELF notes
Date: Wed, 2 Jan 2019 13:06:50 +0000
User-agent: Mutt/1.10.1 (2018-07-13)

On Fri, Dec 21, 2018 at 08:03:49PM +0000, Liam Merwick wrote:
> diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
> index 74679ff8da3a..37d20a3800c1 100644
> --- a/include/hw/elf_ops.h
> +++ b/include/hw/elf_ops.h
> @@ -266,6 +266,7 @@ fail:
>  }
>  
>  static int glue(load_elf, SZ)(const char *name, int fd,
> +                              uint64_t (*elf_note_fn)(void *, void *, bool),
>                                uint64_t (*translate_fn)(void *, uint64_t),
>                                void *translate_opaque,
>                                int must_swab, uint64_t *pentry,
> @@ -496,8 +497,30 @@ static int glue(load_elf, SZ)(const char *name, int fd,
>                  high = addr + mem_size;
>  
>              data = NULL;
> +
> +        } else if (ph->p_type == PT_NOTE && elf_note_fn) {
> +            struct elf_note *nhdr = NULL;
> +
> +            file_size = ph->p_filesz; /* Size of the range of ELF notes */
> +            data = g_malloc0(file_size);
> +            if (ph->p_filesz > 0) {
> +                if (lseek(fd, ph->p_offset, SEEK_SET) < 0) {
> +                    goto fail;
> +                }
> +                if (read(fd, data, file_size) != file_size) {
> +                    goto fail;
> +                }
> +            }
> +
> +            if (nhdr != NULL) {
> +                bool is64 =
> +                    sizeof(struct elf_note) == sizeof(struct elf64_note);
> +                elf_note_fn((void *)nhdr, (void *)&ph->p_align, is64);

How does data get used?

> +            }
> +            g_free(data);

Missing data = NULL to prevent double free later?

Attachment: signature.asc
Description: PGP signature


reply via email to

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