From 6f9b0cd17813f05d262d568e3e225f174ec8a2fe Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Wed, 30 Apr 2014 15:41:39 -0400 Subject: [PATCH] Add check in DwarfReader to avoid exception being caught - In init, don't bother looking for a special note section if the note section size isn't greater than 12 bytes Change-Id: I57d2d7b0229996edcb1b4149c391e91b0472beea Reviewed-on: https://git.eclipse.org/r/25822 Tested-by: Hudson CI Reviewed-by: Marc-Andre Laperle Reviewed-by: Jeff Johnston Tested-by: Jeff Johnston --- .../cdt/utils/debug/dwarf/DwarfReader.java | 74 ++++++++++--------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java index c52462e62b9..7780ba02100 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java @@ -98,45 +98,47 @@ public class DwarfReader extends Dwarf implements ISymbolReader, ICompileOptions for (Section section : sections) { if (section.sh_type == Elf.Section.SHT_NOTE) { ByteBuffer data = section.mapSectionData(); - try { - // Read .note section, looking to see if it is named "GNU" and is of GNU_BUILD_ID type - @SuppressWarnings("unused") - int name_sz = read_4_bytes(data); - int data_sz = read_4_bytes(data); - int note_type = read_4_bytes(data); + if (data.remaining() > 12) { + try { + // Read .note section, looking to see if it is named "GNU" and is of GNU_BUILD_ID type + @SuppressWarnings("unused") + int name_sz = read_4_bytes(data); + int data_sz = read_4_bytes(data); + int note_type = read_4_bytes(data); - String noteName = readString(data); - String buildId = null; - if (noteName.equals("GNU") && note_type == Elf.Section.NT_GNU_BUILD_ID) { //$NON-NLS-1$ - // We have the special GNU build-id note section. Skip over the name to - // a 4-byte boundary. - byte[] byteArray = new byte[data_sz]; - while ((data.position() & 0x3) != 0) - data.get(); - int i = 0; - // Read in the hex bytes from the note section's data. - while (data.hasRemaining() && data_sz-- > 0) { - byteArray[i++] = data.get(); - } - // The build-id location is taken by converting the binary bytes to hex string. - // The first byte is used as a directory specifier (e.g. 51/a4578fe2). - String bName = DatatypeConverter.printHexBinary(byteArray).toLowerCase(); - buildId = bName.substring(0, 2) + "/" + bName.substring(2) + ".debug"; //$NON-NLS-1$ //$NON-NLS-2$ - // The build-id file should be in the special directory /usr/lib/debug/.build-id - IPath buildIdPath = new Path("/usr/lib/debug/.build-id").append(buildId); //$NON-NLS-1$ - File buildIdFile = buildIdPath.toFile(); - if (buildIdFile.exists()) { - // if the debug file exists from above, open it and get the section info from it - Elf debugInfo = new Elf(buildIdFile.getCanonicalPath()); - sections = debugInfo.getSections(); - have_build_id = true; - debugInfoPath = new Path(buildIdFile.getCanonicalPath()).removeLastSegments(1); - break; + String noteName = readString(data); + String buildId = null; + if (noteName.equals("GNU") && note_type == Elf.Section.NT_GNU_BUILD_ID) { //$NON-NLS-1$ + // We have the special GNU build-id note section. Skip over the name to + // a 4-byte boundary. + byte[] byteArray = new byte[data_sz]; + while ((data.position() & 0x3) != 0) + data.get(); + int i = 0; + // Read in the hex bytes from the note section's data. + while (data.hasRemaining() && data_sz-- > 0) { + byteArray[i++] = data.get(); + } + // The build-id location is taken by converting the binary bytes to hex string. + // The first byte is used as a directory specifier (e.g. 51/a4578fe2). + String bName = DatatypeConverter.printHexBinary(byteArray).toLowerCase(); + buildId = bName.substring(0, 2) + "/" + bName.substring(2) + ".debug"; //$NON-NLS-1$ //$NON-NLS-2$ + // The build-id file should be in the special directory /usr/lib/debug/.build-id + IPath buildIdPath = new Path("/usr/lib/debug/.build-id").append(buildId); //$NON-NLS-1$ + File buildIdFile = buildIdPath.toFile(); + if (buildIdFile.exists()) { + // if the debug file exists from above, open it and get the section info from it + Elf debugInfo = new Elf(buildIdFile.getCanonicalPath()); + sections = debugInfo.getSections(); + have_build_id = true; + debugInfoPath = new Path(buildIdFile.getCanonicalPath()).removeLastSegments(1); + break; + } } + } catch (Exception e) { + e.printStackTrace(); + CCorePlugin.log(e); } - } catch (Exception e) { - e.printStackTrace(); - CCorePlugin.log(e); } } }