Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/BinSkim.Rules/DwarfRules/BA3003.EnableStackProtector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,37 @@
if (binary is ElfBinary elf)
{
var validGccCommandLineInfos = new List<DwarfCompileCommandLineInfo>();
foreach (DwarfCompileCommandLineInfo info in binary.CommandLineInfos)

// Some real-world ELF binaries contain DWARF producer entries that
// the DWARF parser does not yet understand (for example, newer
// DW_FORM_* values emitted by recent toolchains, or string-form
// references whose backing section the parser can't resolve).
// In those cases binary.CommandLineInfos throws, which currently
// aborts BA3003 entirely for the target via ERR998. Treat such
// failures as "no DWARF compile-unit information available" so
// the rule can fall back to the symbol-table heuristic below.
//
// The DWARF parser code paths reachable from CommandLineInfos
// can throw any of InvalidOperationException, NotImplementedException,
// ArgumentException, DwarfBufferOverreadException, and bare
// System.Exception (see DwarfCompilationUnit / DwarfMemoryReader /
// DwarfCommonInformationEntry). Because some call sites throw the
// base Exception type directly, we cannot narrow this catch any
// further without re-introducing the ERR998 abort for inputs the
// parser doesn't yet recognise.
List<DwarfCompileCommandLineInfo> commandLineInfos;
try
{
commandLineInfos = binary.CommandLineInfos;
}
#pragma warning disable CA1031 // Do not catch general exception types -- intentional, see comment above.
catch (Exception)
#pragma warning restore CA1031
{
commandLineInfos = new List<DwarfCompileCommandLineInfo>();
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
Comment on lines +178 to +182

foreach (DwarfCompileCommandLineInfo info in commandLineInfos)
{
if (ElfUtility.GetDwarfCommandLineType(info.CommandLine) != DwarfCommandLineType.Gcc)
{
Expand Down
Loading