1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

fixed bug with parsing bad Elf file

This commit is contained in:
David Inglis 2002-08-27 02:58:04 +00:00
parent 8d6b618921
commit 4a84a692d6

View file

@ -32,6 +32,9 @@ public class Elf {
private Symbol[] dynsym_symbols; private Symbol[] dynsym_symbols;
private Section dynsym_sym; private Section dynsym_sym;
private String EMPTY_STRING = "";
public class ELFhdr { public class ELFhdr {
/* e_ident offsets */ /* e_ident offsets */
public final static int EI_MAG0 = 0; public final static int EI_MAG0 = 0;
@ -162,19 +165,22 @@ public class Elf {
public String toString() { public String toString() {
try { try {
if ( section_strtab == null ) { if ( section_strtab == null ) {
section_strtab = new byte[(int)sections[ehdr.e_shstrndx].sh_size]; int size = (int)sections[ehdr.e_shstrndx].sh_size;
if ( size > efile.length() )
return EMPTY_STRING;
section_strtab = new byte[size];
efile.seek(sections[ehdr.e_shstrndx].sh_offset); efile.seek(sections[ehdr.e_shstrndx].sh_offset);
efile.read(section_strtab); efile.read(section_strtab);
} }
int str_size = 0; int str_size = 0;
if ( sh_name > sh_size || ( sh_name + str_size + 1) > section_strtab.length) { if ( sh_name > sh_size || ( sh_name + str_size + 1) > section_strtab.length) {
return ""; return EMPTY_STRING;
} }
while( section_strtab[(int)sh_name + str_size] != 0) while( section_strtab[(int)sh_name + str_size] != 0)
str_size++; str_size++;
return new String(section_strtab, (int)sh_name, str_size); return new String(section_strtab, (int)sh_name, str_size);
} catch (IOException e) { } catch (IOException e) {
return ""; return EMPTY_STRING;
} }
} }
} }
@ -183,7 +189,7 @@ public class Elf {
StringBuffer str = new StringBuffer(); StringBuffer str = new StringBuffer();
byte tmp; byte tmp;
if ( index > section.sh_size ) { if ( index > section.sh_size ) {
return ""; return EMPTY_STRING;
} }
efile.seek(section.sh_offset + index); efile.seek(section.sh_offset + index);
while( true ) { while( true ) {
@ -282,7 +288,7 @@ public class Elf {
Section symstr = sections[(int)sym_section.sh_link]; Section symstr = sections[(int)sym_section.sh_link];
name = cppFilt(string_from_elf_section(symstr, (int)st_name )); name = cppFilt(string_from_elf_section(symstr, (int)st_name ));
} catch (IOException e ) { } catch (IOException e ) {
return ""; return EMPTY_STRING;
} }
} }
return name; return name;
@ -501,11 +507,11 @@ public class Elf {
Section symstr = sections[(int)section.sh_link]; Section symstr = sections[(int)section.sh_link];
name = string_from_elf_section(symstr, (int)d_val); name = string_from_elf_section(symstr, (int)d_val);
} catch (IOException e) { } catch (IOException e) {
name = ""; name = EMPTY_STRING;
} }
break; break;
default: default:
name = ""; name = EMPTY_STRING;
} }
} }
return name; return name;