analyzer: fix ICE on realloc of non-heap [PR104417]

gcc/analyzer/ChangeLog:
	PR analyzer/104417
	* sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
	Remove overzealous assertion.
	(tainted_allocation_size::emit): Likewise.
	(region_model::check_dynamic_size_for_taint): Likewise.

gcc/testsuite/ChangeLog:
	PR analyzer/104417
	* gcc.dg/analyzer/pr104417.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
This commit is contained in:
David Malcolm 2022-02-07 14:00:55 -05:00
parent 9d2c0fad59
commit 0c04ac0e15
2 changed files with 7 additions and 9 deletions

View File

@ -496,9 +496,6 @@ public:
: taint_diagnostic (sm, arg, has_bounds),
m_mem_space (mem_space)
{
gcc_assert (mem_space == MEMSPACE_STACK
|| mem_space == MEMSPACE_HEAP
|| mem_space == MEMSPACE_UNKNOWN);
}
const char *get_kind () const FINAL OVERRIDE
@ -511,9 +508,6 @@ public:
diagnostic_metadata m;
/* "CWE-789: Memory Allocation with Excessive Size Value". */
m.add_cwe (789);
gcc_assert (m_mem_space == MEMSPACE_STACK
|| m_mem_space == MEMSPACE_HEAP
|| m_mem_space == MEMSPACE_UNKNOWN);
// TODO: make use of m_mem_space
if (m_arg)
switch (m_has_bounds)
@ -1055,9 +1049,6 @@ region_model::check_dynamic_size_for_taint (enum memory_space mem_space,
const svalue *size_in_bytes,
region_model_context *ctxt) const
{
gcc_assert (mem_space == MEMSPACE_STACK
|| mem_space == MEMSPACE_HEAP
|| mem_space == MEMSPACE_UNKNOWN);
gcc_assert (size_in_bytes);
gcc_assert (ctxt);

View File

@ -0,0 +1,7 @@
char eparr[1];
void *
warn_realloc_extern_ptrarr_offset (int i, int n)
{
return __builtin_realloc (eparr + i, n); /* { dg-warning "'__builtin_realloc' called on unallocated object 'eparr'" } */
}