| 1 |
/* Integration test of how the execution path looks for |
| 2 |
-Wanalyzer-tainted-assertion with macro-tracking enabled |
| 3 |
(the default). */ |
| 4 |
|
| 5 |
/* { dg-additional-options "-fdiagnostics-show-path-depths" } */ |
| 6 |
/* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ |
| 7 |
|
| 8 |
/* An assertion macro that has a call to a __noreturn__ function. */ |
| 9 |
|
| 10 |
extern void my_assert_fail (const char *expr, const char *file, int line) |
| 11 |
__attribute__ ((__noreturn__)); |
| 12 |
|
| 13 |
#define MY_ASSERT_1(EXPR) \ |
| 14 |
do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0) /* { dg-warning "use of attacked-controlled value in condition for assertion \\\[CWE-617\\\] \\\[-Wanalyzer-tainted-assertion\\\]" } */ |
| 15 |
|
| 16 |
int __attribute__((tainted_args)) |
| 17 |
test_tainted_MY_ASSERT_1 (int n) |
| 18 |
{ |
| 19 |
MY_ASSERT_1 (n > 0); |
| 20 |
return n * n; |
| 21 |
} |
| 22 |
|
| 23 |
/* { dg-begin-multiline-output "" } |
| 24 |
do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0) |
| 25 |
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 26 |
{ dg-end-multiline-output "" } */ |
| 27 |
// note: in expansion of macro 'MY_ASSERT_1' |
| 28 |
/* { dg-begin-multiline-output "" } |
| 29 |
MY_ASSERT_1 (n > 0); |
| 30 |
^~~~~~~~~~~ |
| 31 |
'test_tainted_MY_ASSERT_1': event 1 (depth 0) |
| 32 |
| |
| 33 |
| test_tainted_MY_ASSERT_1 (int n) |
| 34 |
| ^~~~~~~~~~~~~~~~~~~~~~~~ |
| 35 |
| | |
| 36 |
| (1) function 'test_tainted_MY_ASSERT_1' marked with '__attribute__((tainted_args))' |
| 37 |
| |
| 38 |
+--> 'test_tainted_MY_ASSERT_1': event 2 (depth 1) |
| 39 |
| |
| 40 |
| test_tainted_MY_ASSERT_1 (int n) |
| 41 |
| ^~~~~~~~~~~~~~~~~~~~~~~~ |
| 42 |
| | |
| 43 |
| (2) entry to 'test_tainted_MY_ASSERT_1' |
| 44 |
| |
| 45 |
'test_tainted_MY_ASSERT_1': event 3 (depth 1) |
| 46 |
| |
| 47 |
| do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0) |
| 48 |
| ^ |
| 49 |
| | |
| 50 |
| (3) use of attacker-controlled value for control flow |
| 51 |
{ dg-end-multiline-output "" } */ |
| 52 |
// note: in expansion of macro 'MY_ASSERT_1' |
| 53 |
/* { dg-begin-multiline-output "" } |
| 54 |
| MY_ASSERT_1 (n > 0); |
| 55 |
| ^~~~~~~~~~~ |
| 56 |
| |
| 57 |
'test_tainted_MY_ASSERT_1': event 4 (depth 1) |
| 58 |
| |
| 59 |
| do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0) |
| 60 |
| ^ |
| 61 |
| | |
| 62 |
| (4) following 'true' branch (when 'n <= 0')... |
| 63 |
{ dg-end-multiline-output "" } */ |
| 64 |
// note: in expansion of macro 'MY_ASSERT_1' |
| 65 |
/* { dg-begin-multiline-output "" } |
| 66 |
| MY_ASSERT_1 (n > 0); |
| 67 |
| ^~~~~~~~~~~ |
| 68 |
| |
| 69 |
'test_tainted_MY_ASSERT_1': event 5 (depth 1) |
| 70 |
| |
| 71 |
| do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0) |
| 72 |
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 73 |
| | |
| 74 |
| (5) ...to here |
| 75 |
{ dg-end-multiline-output "" } */ |
| 76 |
// note: in expansion of macro 'MY_ASSERT_1' |
| 77 |
/* { dg-begin-multiline-output "" } |
| 78 |
| MY_ASSERT_1 (n > 0); |
| 79 |
| ^~~~~~~~~~~ |
| 80 |
| |
| 81 |
'test_tainted_MY_ASSERT_1': event 6 (depth 1) |
| 82 |
| |
| 83 |
| do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0) |
| 84 |
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 85 |
| | |
| 86 |
| (6) treating 'my_assert_fail' as an assertion failure handler due to '__attribute__((__noreturn__))' |
| 87 |
{ dg-end-multiline-output "" } */ |
| 88 |
// note: in expansion of macro 'MY_ASSERT_1' |
| 89 |
/* { dg-begin-multiline-output "" } |
| 90 |
| MY_ASSERT_1 (n > 0); |
| 91 |
| ^~~~~~~~~~~ |
| 92 |
| |
| 93 |
{ dg-end-multiline-output "" } */ |