bool subclass_equal_p (const pending_diagnostic &base_other) const OVERRIDE
{
- return same_tree_p (m_arg, ((const taint_diagnostic &)base_other).m_arg);
+ const taint_diagnostic &other = (const taint_diagnostic &)base_other;
+ return (same_tree_p (m_arg, other.m_arg)
+ && m_has_bounds == other.m_has_bounds);
}
label_text describe_state_change (const evdesc::state_change &change)
return "tainted_allocation_size";
}
+ bool subclass_equal_p (const pending_diagnostic &base_other) const OVERRIDE
+ {
+ if (!taint_diagnostic::subclass_equal_p (base_other))
+ return false;
+ const tainted_allocation_size &other
+ = (const tainted_allocation_size &)base_other;
+ return m_mem_space == other.m_mem_space;
+ }
+
int get_controlling_option () const FINAL OVERRIDE
{
return OPT_Wanalyzer_tainted_allocation_size;
diagnostic_metadata m;
/* "CWE-789: Memory Allocation with Excessive Size Value". */
m.add_cwe (789);
- // TODO: make use of m_mem_space
+
+ bool warned;
if (m_arg)
switch (m_has_bounds)
{
default:
gcc_unreachable ();
case BOUNDS_NONE:
- return warning_meta (rich_loc, m, get_controlling_option (),
- "use of attacker-controlled value %qE as"
- " allocation size without bounds checking",
- m_arg);
+ warned = warning_meta (rich_loc, m, get_controlling_option (),
+ "use of attacker-controlled value %qE as"
+ " allocation size without bounds checking",
+ m_arg);
break;
case BOUNDS_UPPER:
- return warning_meta (rich_loc, m, get_controlling_option (),
- "use of attacker-controlled value %qE as"
- " allocation size without lower-bounds checking",
- m_arg);
+ warned = warning_meta (rich_loc, m, get_controlling_option (),
+ "use of attacker-controlled value %qE as"
+ " allocation size without"
+ " lower-bounds checking",
+ m_arg);
break;
case BOUNDS_LOWER:
- return warning_meta (rich_loc, m, get_controlling_option (),
- "use of attacker-controlled value %qE as"
- " allocation size without upper-bounds checking",
- m_arg);
+ warned = warning_meta (rich_loc, m, get_controlling_option (),
+ "use of attacker-controlled value %qE as"
+ " allocation size without"
+ " upper-bounds checking",
+ m_arg);
break;
}
else
default:
gcc_unreachable ();
case BOUNDS_NONE:
- return warning_meta (rich_loc, m, get_controlling_option (),
- "use of attacker-controlled value as"
- " allocation size without bounds"
- " checking");
+ warned = warning_meta (rich_loc, m, get_controlling_option (),
+ "use of attacker-controlled value as"
+ " allocation size without bounds"
+ " checking");
break;
case BOUNDS_UPPER:
- return warning_meta (rich_loc, m, get_controlling_option (),
- "use of attacker-controlled value as"
- " allocation size without lower-bounds"
- " checking");
+ warned = warning_meta (rich_loc, m, get_controlling_option (),
+ "use of attacker-controlled value as"
+ " allocation size without"
+ " lower-bounds checking");
break;
case BOUNDS_LOWER:
- return warning_meta (rich_loc, m, get_controlling_option (),
- "use of attacker-controlled value as"
- " allocation size without upper-bounds"
- " checking");
+ warned = warning_meta (rich_loc, m, get_controlling_option (),
+ "use of attacker-controlled value as"
+ " allocation size without"
+ " upper-bounds checking");
break;
}
+ if (warned)
+ {
+ location_t loc = rich_loc->get_loc ();
+ switch (m_mem_space)
+ {
+ default:
+ break;
+ case MEMSPACE_STACK:
+ inform (loc, "stack-based allocation");
+ break;
+ case MEMSPACE_HEAP:
+ inform (loc, "heap-based allocation");
+ break;
+ }
+ }
+ return warned;
}
label_text describe_final_event (const evdesc::final_event &ev) FINAL OVERRIDE