]> gcc.gnu.org Git - gcc.git/commitdiff
analyzer: fix ICE due to sm-state origin being purged (PR 93382)
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 22 Jan 2020 14:37:18 +0000 (09:37 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 23 Jan 2020 02:06:45 +0000 (21:06 -0500)
The ICE in PR analyzer/93382 is a validation error.

The global variable "idx" acquires a "tainted" state from local array
n1[0].  When the frame is popped, the svalue for n1[0] is purged, but
the "taint" sm_state_map's entry for "idx" has a svalue_id referencing
the now-purged svalue.  This is caught by program_state::validate as an
assertion failure.

This patch fixes the issue by resetting the origin id within
sm_state_map entries for the case where the origin id has been purged.

gcc/analyzer/ChangeLog:
PR analyzer/93382
* program-state.cc (sm_state_map::on_svalue_purge): If the
entry survives, but the origin is being purged, then reset the
origin to null.

gcc/testsuite/ChangeLog:
PR analyzer/93382
* gcc.dg/analyzer/pr93382.c: New test.

gcc/analyzer/ChangeLog
gcc/analyzer/program-state.cc
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/analyzer/pr93382.c [new file with mode: 0644]

index 52d959d2cdba7d53d05741b7c267b2ee0510dca0..16613e4f9b9375e5a08af49e9736817a7012443e 100644 (file)
@@ -1,3 +1,10 @@
+2020-01-22  David Malcolm  <dmalcolm@redhat.com>
+
+       PR analyzer/93382
+       * program-state.cc (sm_state_map::on_svalue_purge): If the
+       entry survives, but the origin is being purged, then reset the
+       origin to null.
+
 2020-01-22  David Malcolm  <dmalcolm@redhat.com>
 
        * sm-signal.cc: Fix nesting of CHECKING_P and namespace ana.
index 72daee6428e9dda4cd2ccc79a101e743e67f6eae..ba19ad1490e03507c2c2c9fda0c98b5ae3e71ac6 100644 (file)
@@ -453,6 +453,11 @@ sm_state_map::on_svalue_purge (const state_machine &sm,
 
          to_remove.safe_push (dst_sid);
        }
+      else if ((*iter).second.m_origin.as_int () >= first_unused_sid.as_int ())
+       {
+         /* If the origin svalue is being purged, then reset it to null.  */
+         (*iter).second.m_origin = svalue_id::null ();
+       }
     }
 
   int i;
index 5160e86fc9d87dc5e94e3037ca4c4e9a3d3d342d..eeeb1209d19b3125a230c461944600e022c969f5 100644 (file)
@@ -1,3 +1,8 @@
+2020-01-22  David Malcolm  <dmalcolm@redhat.com>
+
+       PR analyzer/93382
+       * gcc.dg/analyzer/pr93382.c: New test.
+
 2020-01-22  Andrew Pinski  <apinski@marvell.com>
 
        * gcc.dg/tree-ssa/pr88497-1.c: Move to ...
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr93382.c b/gcc/testsuite/gcc.dg/analyzer/pr93382.c
new file mode 100644 (file)
index 0000000..7d18d16
--- /dev/null
@@ -0,0 +1,25 @@
+typedef __SIZE_TYPE__ size_t;
+
+int idx;
+void *fp;
+
+size_t
+fread (void *, size_t, size_t, void *);
+
+void
+ql (void)
+{
+  int n1[1];
+
+  fread (n1, sizeof (n1[0]), 1, fp); /* { dg-message "'n1' gets an unchecked value here" } */
+  idx = n1[0]; /* { dg-message "'idx' has an unchecked value here (from 'n1')" */
+}
+
+int arr[10];
+       
+int
+pl (void)
+{
+  ql ();
+  return arr[idx]; /* { dg-warning "use of tainted value 'idx' in array lookup without bounds checking" } */
+}
This page took 0.0907210000000001 seconds and 5 git commands to generate.