[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 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. 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"). Jan > #endif > > /* Calculate the required additional kernel space for the elf image */ _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |