gcc/analyzer/ChangeLog:
* sm-taint.cc (taint_state_machine::alt_get_inherited_state): Fix
handling of TRUNC_MOD_EXPR.
gcc/testsuite/ChangeLog:
* c-c++-common/analyzer/taint-modulus-1.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
case MULT_EXPR:
case POINTER_PLUS_EXPR:
case TRUNC_DIV_EXPR:
- case TRUNC_MOD_EXPR:
{
state_t arg0_state = map.get_state (arg0, ext_state);
state_t arg1_state = map.get_state (arg1, ext_state);
}
break;
+ case TRUNC_MOD_EXPR:
+ {
+ /* The left-hand side of X % Y can be sanitized by
+ the operation. */
+ return map.get_state (arg1, ext_state);
+ }
+ break;
+
case BIT_AND_EXPR:
case RSHIFT_EXPR:
return NULL;
--- /dev/null
+#define SIZE 16
+char buf[SIZE];
+
+__attribute__ ((tainted_args))
+char test_sanitized_by_modulus (int val)
+{
+ return buf[val % SIZE]; /* { dg-bogus "use of attacker-controlled value" } */
+}