1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 00:35:49 +02:00

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>
This commit is contained in:
Jeff Johnston 2014-04-30 15:41:39 -04:00
parent 82853c889d
commit 6f9b0cd178

View file

@ -98,45 +98,47 @@ public class DwarfReader extends Dwarf implements ISymbolReader, ICompileOptions
for (Section section : sections) { for (Section section : sections) {
if (section.sh_type == Elf.Section.SHT_NOTE) { if (section.sh_type == Elf.Section.SHT_NOTE) {
ByteBuffer data = section.mapSectionData(); ByteBuffer data = section.mapSectionData();
try { if (data.remaining() > 12) {
// Read .note section, looking to see if it is named "GNU" and is of GNU_BUILD_ID type try {
@SuppressWarnings("unused") // Read .note section, looking to see if it is named "GNU" and is of GNU_BUILD_ID type
int name_sz = read_4_bytes(data); @SuppressWarnings("unused")
int data_sz = read_4_bytes(data); int name_sz = read_4_bytes(data);
int note_type = read_4_bytes(data); int data_sz = read_4_bytes(data);
int note_type = read_4_bytes(data);
String noteName = readString(data); String noteName = readString(data);
String buildId = null; String buildId = null;
if (noteName.equals("GNU") && note_type == Elf.Section.NT_GNU_BUILD_ID) { //$NON-NLS-1$ 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 // We have the special GNU build-id note section. Skip over the name to
// a 4-byte boundary. // a 4-byte boundary.
byte[] byteArray = new byte[data_sz]; byte[] byteArray = new byte[data_sz];
while ((data.position() & 0x3) != 0) while ((data.position() & 0x3) != 0)
data.get(); data.get();
int i = 0; int i = 0;
// Read in the hex bytes from the note section's data. // Read in the hex bytes from the note section's data.
while (data.hasRemaining() && data_sz-- > 0) { while (data.hasRemaining() && data_sz-- > 0) {
byteArray[i++] = data.get(); byteArray[i++] = data.get();
} }
// The build-id location is taken by converting the binary bytes to hex string. // 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). // The first byte is used as a directory specifier (e.g. 51/a4578fe2).
String bName = DatatypeConverter.printHexBinary(byteArray).toLowerCase(); String bName = DatatypeConverter.printHexBinary(byteArray).toLowerCase();
buildId = bName.substring(0, 2) + "/" + bName.substring(2) + ".debug"; //$NON-NLS-1$ //$NON-NLS-2$ 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 // 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$ IPath buildIdPath = new Path("/usr/lib/debug/.build-id").append(buildId); //$NON-NLS-1$
File buildIdFile = buildIdPath.toFile(); File buildIdFile = buildIdPath.toFile();
if (buildIdFile.exists()) { if (buildIdFile.exists()) {
// if the debug file exists from above, open it and get the section info from it // if the debug file exists from above, open it and get the section info from it
Elf debugInfo = new Elf(buildIdFile.getCanonicalPath()); Elf debugInfo = new Elf(buildIdFile.getCanonicalPath());
sections = debugInfo.getSections(); sections = debugInfo.getSections();
have_build_id = true; have_build_id = true;
debugInfoPath = new Path(buildIdFile.getCanonicalPath()).removeLastSegments(1); debugInfoPath = new Path(buildIdFile.getCanonicalPath()).removeLastSegments(1);
break; break;
}
} }
} catch (Exception e) {
e.printStackTrace();
CCorePlugin.log(e);
} }
} catch (Exception e) {
e.printStackTrace();
CCorePlugin.log(e);
} }
} }
} }