From 8daef5ac9c98cc79dfba7050c054ddbcd72cb5b0 Mon Sep 17 00:00:00 2001 From: David Inglis Date: Mon, 28 Jul 2003 13:36:57 +0000 Subject: [PATCH] added range checks for section string --- .../utils/org/eclipse/cdt/utils/elf/Elf.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java index f7f0297ce5f..e54a63e7ad5 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java @@ -167,6 +167,8 @@ public class Elf { public String toString() { try { if ( section_strtab == null ) { + if ( ehdr.e_shstrndx > sections.length || ehdr.e_shstrndx < 0) + return EMPTY_STRING; int size = (int)sections[ehdr.e_shstrndx].sh_size; if ( size <= 0 || size > efile.length() ) return EMPTY_STRING; @@ -555,18 +557,18 @@ public class Elf { } private void commonSetup( String file, long offset, boolean filton ) - throws IOException + throws IOException { this.cppFiltEnabled = filton; - efile = new ERandomAccessFile(file, "r"); - efile.setFileOffset( offset ); try { + efile = new ERandomAccessFile(file, "r"); + efile.setFileOffset( offset ); ehdr = new ELFhdr(); this.file = file; } finally { if ( ehdr == null ) { - efile.close(); + dispose(); } } }