#include "analyzer/program-state.h"
#include "analyzer/pending-diagnostic.h"
#include "analyzer/constraint-manager.h"
+#include "diagnostic-format-sarif.h"
#if ENABLE_ANALYZER
BOUNDS_LOWER
};
+static const char *
+bounds_to_str (enum bounds b)
+{
+ switch (b)
+ {
+ default:
+ gcc_unreachable ();
+ case BOUNDS_NONE:
+ return "BOUNDS_NONE";
+ case BOUNDS_UPPER:
+ return "BOUNDS_UPPER";
+ case BOUNDS_LOWER:
+ return "BOUNDS_LOWER";
+ }
+}
+
/* An experimental state machine, for tracking "taint": unsanitized uses
of data potentially under an attacker's control. */
return diagnostic_event::meaning ();
}
+ void maybe_add_sarif_properties (sarif_object &result_obj)
+ const override
+ {
+ sarif_property_bag &props = result_obj.get_or_create_properties ();
+#define PROPERTY_PREFIX "gcc/analyzer/taint_diagnostic/"
+ props.set (PROPERTY_PREFIX "arg", tree_to_json (m_arg));
+ props.set_string (PROPERTY_PREFIX "has_bounds",
+ bounds_to_str (m_has_bounds));
+#undef PROPERTY_PREFIX
+ }
+
protected:
const taint_state_machine &m_sm;
tree m_arg;
{
public:
tainted_offset (const taint_state_machine &sm, tree arg,
- enum bounds has_bounds)
- : taint_diagnostic (sm, arg, has_bounds)
+ enum bounds has_bounds,
+ const svalue *offset)
+ : taint_diagnostic (sm, arg, has_bounds),
+ m_offset (offset)
{}
const char *get_kind () const final override { return "tainted_offset"; }
" checking");
}
}
+
+ void maybe_add_sarif_properties (sarif_object &result_obj)
+ const final override
+ {
+ taint_diagnostic::maybe_add_sarif_properties (result_obj);
+ sarif_property_bag &props = result_obj.get_or_create_properties ();
+#define PROPERTY_PREFIX "gcc/analyzer/tainted_offset/"
+ props.set (PROPERTY_PREFIX "offset", m_offset->to_json ());
+#undef PROPERTY_PREFIX
+ }
+
+private:
+ const svalue *m_offset;
};
/* Concrete taint_diagnostic subclass for reporting attacker-controlled
if (taint_sm.get_taint (state, effective_type, &b))
{
tree arg = get_representative_tree (offset);
- ctxt->warn (make_unique<tainted_offset> (taint_sm, arg, b));
+ ctxt->warn (make_unique<tainted_offset> (taint_sm, arg, b,
+ offset));
}
}
break;