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

Re: [Xen-devel] [PATCH v4 06/25] libelf-loader: introduce elf_load_image



On Tue, 10 Jan 2012, Jan Beulich wrote:
> >>> On 09.01.12 at 18:59, <stefano.stabellini@xxxxxxxxxxxxx> wrote:
> > --- a/xen/common/libelf/libelf-loader.c
> > +++ b/xen/common/libelf/libelf-loader.c
> > @@ -107,11 +107,32 @@ void elf_set_log(struct elf_binary *elf, 
> > elf_log_callback *log_callback,
> >      elf->log_caller_data = log_caller_data;
> >      elf->verbose = verbose;
> >  }
> > +
> > +static int elf_load_image(void *dst, const void *src, uint64_t filesz, 
> > uint64_t memsz)
> > +{
> > +    memcpy(dst, src, filesz);
> > +    memset(dst + filesz, 0, memsz - filesz);
> > +    return 0;
> > +}
> >  #else
> > +#include <asm/guest_access.h>
> > +
> >  void elf_set_verbose(struct elf_binary *elf)
> >  {
> >      elf->verbose = 1;
> >  }
> > +
> > +static int elf_load_image(void *dst, const void *src, uint64_t filesz, 
> > uint64_t memsz)
> > +{
> > +    int rc;
> > +    rc = raw_copy_to_guest(dst, src, filesz);
> > +    if ( rc != 0 )
> > +        return -rc;
> > +    rc = raw_clear_guest(dst + filesz, memsz - filesz);
> > +    if ( rc != 0 )
> > +        return -rc;
> > +    return 0;
> > +}
> 
> I'm afraid a little more care is needed here: filesz and memsz being
> 64-bit values permits them to overflow the "long" of the functions
> called. I think simply checking that both values fit in an unsigned long
> will do for now.

OK

> Also, if you want to return a meaningful error code here, you also
> need to consider that fact as well as the counts being unsigned (or
> otherwise you could e.g. just return "bool").

I'll just return -1, to be consistent with elf_init

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.