]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: fix ICE on division of tainted floating-point values [PR110700]
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 19 Jul 2023 21:55:09 +0000 (17:55 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 19 Jul 2023 21:55:09 +0000 (17:55 -0400)
gcc/analyzer/ChangeLog:
PR analyzer/110700
* region-model-manager.cc
(region_model_manager::get_or_create_int_cst): Assert that we have
an integral or pointer type.
* sm-taint.cc (taint_state_machine::check_for_tainted_divisor):
Don't check non-integral types.

gcc/testsuite/ChangeLog:
PR analyzer/110700
* gcc.dg/analyzer/taint-divisor-2.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/region-model-manager.cc
gcc/analyzer/sm-taint.cc
gcc/testsuite/gcc.dg/analyzer/taint-divisor-2.c [new file with mode: 0644]

index 4f11ef4bd29363739580b05a0eb31052c507fd84..e43b99ae0bae9fe4a11ed91d47fc1da001d37fea 100644 (file)
@@ -234,6 +234,7 @@ region_model_manager::get_or_create_int_cst (tree type,
                                             const poly_wide_int_ref &cst)
 {
   gcc_assert (type);
+  gcc_assert (INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type));
   tree tree_cst = wide_int_to_tree (type, cst);
   return get_or_create_constant_svalue (tree_cst);
 }
index 6d28d1f6f6541c5908866137a62e973521f2768b..09c1e9368cdf0ba7765db0108db9b4c253867e0b 100644 (file)
@@ -1344,6 +1344,12 @@ taint_state_machine::check_for_tainted_divisor (sm_context *sm_ctxt,
     return;
 
   tree divisor_expr = gimple_assign_rhs2 (assign);;
+
+  /* Until we track conditions on floating point values, we can't check to
+     see if they've been checked against zero.  */
+  if (!INTEGRAL_TYPE_P (TREE_TYPE (divisor_expr)))
+    return;
+
   const svalue *divisor_sval = old_model->get_rvalue (divisor_expr, NULL);
 
   state_t state = sm_ctxt->get_state (assign, divisor_sval);
diff --git a/gcc/testsuite/gcc.dg/analyzer/taint-divisor-2.c b/gcc/testsuite/gcc.dg/analyzer/taint-divisor-2.c
new file mode 100644 (file)
index 0000000..de9a1cb
--- /dev/null
@@ -0,0 +1,13 @@
+// TODO: remove need for this option:
+/* { dg-additional-options "-fanalyzer-checker=taint" } */
+
+#include "analyzer-decls.h"
+
+__attribute__ ((tainted_args))
+double pr110700 (double x, double y)
+{
+  /* Ideally we'd complain here with -Wanalyzer-tainted-divisor, but
+     until we track conditions on floating point values, we can't check to
+     see if they've been checked against zero.  */
+  return x / y;
+}