(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
analyzer/
taint-assert-system-header.c
       1  /* Integration test of how the execution path looks for
       2     -Wanalyzer-tainted-assertion with macro-tracking enabled
       3     (the default), where the assertion macro is defined in
       4     a system header.  */
       5  
       6  // TODO: remove need for this option
       7  /* { dg-additional-options "-fanalyzer-checker=taint" } */
       8  
       9  /* { dg-additional-options "-fdiagnostics-show-path-depths" } */
      10  /* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
      11  
      12  /* An assertion macro that has a call to a __noreturn__ function.  */
      13  
      14  /* This is marked as a system header.  */
      15  #include "test-assert.h"
      16  
      17  int __attribute__((tainted_args))
      18  test_tainted_assert (int n)
      19  {
      20    assert (n > 0); /* { dg-warning "use of attacked-controlled value in condition for assertion \\\[CWE-617\\\] \\\[-Wanalyzer-tainted-assertion\\\]" } */
      21    return n * n;
      22  }
      23  
      24  /* { dg-begin-multiline-output "" }
      25     assert (n > 0);
      26     ^~~~~~
      27    'test_tainted_assert': event 1 (depth 0)
      28      |
      29      | test_tainted_assert (int n)
      30      | ^~~~~~~~~~~~~~~~~~~
      31      | |
      32      | (1) function 'test_tainted_assert' marked with '__attribute__((tainted_args))'
      33      |
      34      +--> 'test_tainted_assert': event 2 (depth 1)
      35             |
      36             | test_tainted_assert (int n)
      37             | ^~~~~~~~~~~~~~~~~~~
      38             | |
      39             | (2) entry to 'test_tainted_assert'
      40             |
      41           'test_tainted_assert': events 3-6 (depth 1)
      42             |
      43             |
      44             |   do { if (!(EXPR)) __assert_fail (#EXPR, __FILE__, __LINE__); } while (0)
      45             |           ^         ~~~~~~~~~~~~~
      46             |           |         |
      47             |           |         (5) ...to here
      48             |           |         (6) treating '__assert_fail' as an assertion failure handler due to '__attribute__((__noreturn__))'
      49             |           (3) use of attacker-controlled value for control flow
      50             |           (4) following 'true' branch (when 'n <= 0')...
      51             |
      52     { dg-end-multiline-output "" } */