Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2014-04-30 19:41:39 +0000
committerJeff Johnston2014-04-30 21:34:35 +0000
commit6f9b0cd17813f05d262d568e3e225f174ec8a2fe (patch)
treedc501a46de15c788eb5e630be088a50e028311f8 /core/org.eclipse.cdt.core/utils
parent82853c889d9dfd4aba419ce84fd4fba5b7c8f555 (diff)
downloadorg.eclipse.cdt-6f9b0cd17813f05d262d568e3e225f174ec8a2fe.tar.gz
org.eclipse.cdt-6f9b0cd17813f05d262d568e3e225f174ec8a2fe.tar.xz
org.eclipse.cdt-6f9b0cd17813f05d262d568e3e225f174ec8a2fe.zip
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 <marc-andre.laperle@ericsson.com> Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> Tested-by: Jeff Johnston <jjohnstn@redhat.com>
Diffstat (limited to 'core/org.eclipse.cdt.core/utils')
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/debug/dwarf/DwarfReader.java74
1 files 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);
}
}
}

Back to the top