ia64/xen-unstable

changeset 10633:461fc0bf91f5

Provide more specific and helpful error messages during ELF loading.

Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com>
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jun 30 22:19:08 2006 +0100 (2006-06-30)
parents c14f26a7b0bc
children cda7b6017a76
files tools/libxc/xc_load_elf.c
line diff
     1.1 --- a/tools/libxc/xc_load_elf.c	Fri Jun 30 22:18:01 2006 +0100
     1.2 +++ b/tools/libxc/xc_load_elf.c	Fri Jun 30 22:19:08 2006 +0100
     1.3 @@ -170,7 +170,11 @@ static int parseelfimage(const char *ima
     1.4      elf_pa_off = elf_pa_off_defined ? strtoull(p+17, &p, 0) : virt_base;
     1.5  
     1.6      if ( elf_pa_off_defined && !virt_base_defined )
     1.7 -        goto bad_image;
     1.8 +    {
     1.9 +        ERROR("Neither ELF_PADDR_OFFSET nor VIRT_BASE found in __xen_guest"
    1.10 +              " section.");
    1.11 +        return -EINVAL;
    1.12 +    }
    1.13  
    1.14      for ( h = 0; h < ehdr->e_phnum; h++ )
    1.15      {
    1.16 @@ -179,7 +183,11 @@ static int parseelfimage(const char *ima
    1.17              continue;
    1.18          vaddr = phdr->p_paddr - elf_pa_off + virt_base;
    1.19          if ( (vaddr + phdr->p_memsz) < vaddr )
    1.20 -            goto bad_image;
    1.21 +        {
    1.22 +            ERROR("ELF program header %d is too large.", h);
    1.23 +            return -EINVAL;
    1.24 +        }
    1.25 +
    1.26          if ( vaddr < kernstart )
    1.27              kernstart = vaddr;
    1.28          if ( (vaddr + phdr->p_memsz) > kernend )
    1.29 @@ -202,7 +210,10 @@ static int parseelfimage(const char *ima
    1.30           (dsi->v_kernentry < kernstart) ||
    1.31           (dsi->v_kernentry > kernend) ||
    1.32           (dsi->v_start > kernstart) )
    1.33 -        goto bad_image;
    1.34 +    {
    1.35 +        ERROR("ELF start or entries are out of bounds.");
    1.36 +        return -EINVAL;
    1.37 +    }
    1.38  
    1.39      if ( (p = strstr(guestinfo, "BSD_SYMTAB")) != NULL )
    1.40          dsi->load_symtab = 1;
    1.41 @@ -214,10 +225,6 @@ static int parseelfimage(const char *ima
    1.42      loadelfsymtab(image, 0, 0, NULL, dsi);
    1.43  
    1.44      return 0;
    1.45 -
    1.46 - bad_image:
    1.47 -    ERROR("Malformed ELF image.");
    1.48 -    return -EINVAL;
    1.49  }
    1.50  
    1.51  static int