Debian Codegraph @

gcc/testsuite/sarif-replay.dg/2.1.0-valid/signal-1.c.sarif

raw
1 /* Test a replay of a .sarif file generated from GCC testsuite.
2
3 The dg directives were stripped out from the generated .sarif
4 to avoid confusing DejaGnu for this test. */
5
6 {"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
7 "version": "2.1.0",
8 "runs": [{"tool": {"driver": {"name": "GNU C17",
9 "fullName": "GNU C17 (GCC) version 15.0.0 20240709 (experimental) (x86_64-pc-linux-gnu)",
10 "version": "15.0.0 20240709 (experimental)",
11 "informationUri": "https://gcc.gnu.org/gcc-15/",
12 "rules": [{"id": "-Wanalyzer-unsafe-call-within-signal-handler",
13 "helpUri": "https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html#index-Wanalyzer-unsafe-call-within-signal-handler"}]}},
14 "taxonomies": [{"name": "CWE",
15 "version": "4.7",
16 "organization": "MITRE",
17 "shortDescription": {"text": "The MITRE Common Weakness Enumeration"},
18 "taxa": [{"id": "479",
19 "helpUri": "https://cwe.mitre.org/data/definitions/479.html"}]}],
20 "invocations": [{"executionSuccessful": true,
21 "toolExecutionNotifications": []}],
22 "originalUriBaseIds": {"PWD": {"uri": "file:///home/david/coding/gcc-newgit-more-taint/build/gcc/"}},
23 "artifacts": [{"location": {"uri": "../../src/gcc/testsuite/gcc.dg/analyzer/signal-1.c",
24 "uriBaseId": "PWD"},
25 "sourceLanguage": "c",
26 "contents": {"text": "/* Example of a bad call within a signal handler.\n 'handler' calls 'custom_logger' which calls 'fprintf', and 'fprintf' is\n not allowed from a signal handler. */\n\n\n#include <stdio.h>\n#include <signal.h>\n\nextern void body_of_program(void);\n\nvoid custom_logger(const char *msg)\n{\n fprintf(stderr, \"LOG: %s\", msg);\n}\n\nstatic void handler(int signum)\n{\n custom_logger(\"got signal\");\n}\n\nint main(int argc, const char *argv)\n{\n custom_logger(\"started\");\n\n signal(SIGINT, handler);\n\n body_of_program();\n\n custom_logger(\"stopped\");\n\n return 0;\n}\n"},
27 "roles": ["analysisTarget",
28 "tracedFile"]}],
29 "results": [{"ruleId": "-Wanalyzer-unsafe-call-within-signal-handler",
30 "taxa": [{"id": "479",
31 "toolComponent": {"name": "cwe"}}],
32 "properties": {"gcc/analyzer/saved_diagnostic/sm": "signal",
33 "gcc/analyzer/saved_diagnostic/enode": 57,
34 "gcc/analyzer/saved_diagnostic/snode": 11,
35 "gcc/analyzer/saved_diagnostic/state": "in_signal_handler",
36 "gcc/analyzer/saved_diagnostic/idx": 0},
37 "level": "warning",
38 "message": {"text": "call to ‘fprintf’ from within signal handler"},
39 "locations": [{"physicalLocation": {"artifactLocation": {"uri": "../../src/gcc/testsuite/gcc.dg/analyzer/signal-1.c",
40 "uriBaseId": "PWD"},
41 "region": {"startLine": 13,
42 "startColumn": 3,
43 "endColumn": 34},
44 "contextRegion": {"startLine": 13,
45 "snippet": {"text": " fprintf(stderr, \"LOG: %s\", msg);\n"}}},
46 "logicalLocations": [{"name": "custom_logger",
47 "fullyQualifiedName": "custom_logger",
48 "decoratedName": "custom_logger",
49 "kind": "function"}]}],
50 "codeFlows": [{"threadFlows": [{"id": "main",
51 "locations": [{"properties": {"gcc/analyzer/checker_event/emission_id": "(1)",
52 "gcc/analyzer/checker_event/kind": "EK_FUNCTION_ENTRY"},
53 "location": {"physicalLocation": {"artifactLocation": {"uri": "../../src/gcc/testsuite/gcc.dg/analyzer/signal-1.c",
54 "uriBaseId": "PWD"},
55 "region": {"startLine": 21,
56 "startColumn": 5,
57 "endColumn": 9},
58 "contextRegion": {"startLine": 21,
59 "snippet": {"text": "int main(int argc, const char *argv)\n"}}},
60 "logicalLocations": [{"name": "main",
61 "fullyQualifiedName": "main",
62 "decoratedName": "main",
63 "kind": "function"}],
64 "message": {"text": "entry to ‘main’"}},
65 "kinds": ["enter",
66 "function"],
67 "nestingLevel": 1,
68 "executionOrder": 1},
69 {"properties": {"gcc/analyzer/checker_event/emission_id": "(2)",
70 "gcc/analyzer/checker_event/kind": "EK_STATE_CHANGE"},
71 "location": {"physicalLocation": {"artifactLocation": {"uri": "../../src/gcc/testsuite/gcc.dg/analyzer/signal-1.c",
72 "uriBaseId": "PWD"},
73 "region": {"startLine": 25,
74 "startColumn": 3,
75 "endColumn": 26},
76 "contextRegion": {"startLine": 25,
77 "snippet": {"text": " signal(SIGINT, handler);\n"}}},
78 "logicalLocations": [{"name": "main",
79 "fullyQualifiedName": "main",
80 "decoratedName": "main",
81 "kind": "function"}],
82 "message": {"text": "registering ‘handler’ as signal handler"}},
83 "nestingLevel": 1,
84 "executionOrder": 2},
85 {"properties": {"gcc/analyzer/checker_event/emission_id": "(3)",
86 "gcc/analyzer/checker_event/kind": "EK_CUSTOM"},
87 "location": {"message": {"text": "later on, when the signal is delivered to the process"}},
88 "nestingLevel": 0,
89 "executionOrder": 3},
90 {"properties": {"gcc/analyzer/checker_event/emission_id": "(4)",
91 "gcc/analyzer/checker_event/kind": "EK_FUNCTION_ENTRY"},
92 "location": {"physicalLocation": {"artifactLocation": {"uri": "../../src/gcc/testsuite/gcc.dg/analyzer/signal-1.c",
93 "uriBaseId": "PWD"},
94 "region": {"startLine": 16,
95 "startColumn": 13,
96 "endColumn": 20},
97 "contextRegion": {"startLine": 16,
98 "snippet": {"text": "static void handler(int signum)\n"}}},
99 "logicalLocations": [{"name": "handler",
100 "fullyQualifiedName": "handler",
101 "decoratedName": "handler",
102 "kind": "function"}],
103 "message": {"text": "entry to ‘handler’"}},
104 "kinds": ["enter",
105 "function"],
106 "nestingLevel": 1,
107 "executionOrder": 4},
108 {"properties": {"gcc/analyzer/checker_event/emission_id": "(5)",
109 "gcc/analyzer/checker_event/kind": "EK_CALL_EDGE",
110 "gcc/analyzer/superedge_event/superedge": {"kind": "SUPEREDGE_CALL",
111 "src_idx": 7,
112 "dst_idx": 10,
113 "desc": "call"}},
114 "location": {"physicalLocation": {"artifactLocation": {"uri": "../../src/gcc/testsuite/gcc.dg/analyzer/signal-1.c",
115 "uriBaseId": "PWD"},
116 "region": {"startLine": 18,
117 "startColumn": 3,
118 "endColumn": 30},
119 "contextRegion": {"startLine": 18,
120 "snippet": {"text": " custom_logger(\"got signal\");\n"}}},
121 "logicalLocations": [{"name": "handler",
122 "fullyQualifiedName": "handler",
123 "decoratedName": "handler",
124 "kind": "function"}],
125 "message": {"text": "calling ‘custom_logger’ from ‘handler’"}},
126 "kinds": ["call",
127 "function"],
128 "nestingLevel": 1,
129 "executionOrder": 5},
130 {"properties": {"gcc/analyzer/checker_event/emission_id": "(6)",
131 "gcc/analyzer/checker_event/kind": "EK_FUNCTION_ENTRY"},
132 "location": {"physicalLocation": {"artifactLocation": {"uri": "../../src/gcc/testsuite/gcc.dg/analyzer/signal-1.c",
133 "uriBaseId": "PWD"},
134 "region": {"startLine": 11,
135 "startColumn": 6,
136 "endColumn": 19},
137 "contextRegion": {"startLine": 11,
138 "snippet": {"text": "void custom_logger(const char *msg)\n"}}},
139 "logicalLocations": [{"name": "custom_logger",
140 "fullyQualifiedName": "custom_logger",
141 "decoratedName": "custom_logger",
142 "kind": "function"}],
143 "message": {"text": "entry to ‘custom_logger’"}},
144 "kinds": ["enter",
145 "function"],
146 "nestingLevel": 2,
147 "executionOrder": 6},
148 {"properties": {"gcc/analyzer/checker_event/emission_id": "(7)",
149 "gcc/analyzer/checker_event/kind": "EK_WARNING"},
150 "location": {"physicalLocation": {"artifactLocation": {"uri": "../../src/gcc/testsuite/gcc.dg/analyzer/signal-1.c",
151 "uriBaseId": "PWD"},
152 "region": {"startLine": 13,
153 "startColumn": 3,
154 "endColumn": 34},
155 "contextRegion": {"startLine": 13,
156 "snippet": {"text": " fprintf(stderr, \"LOG: %s\", msg);\n"}}},
157 "logicalLocations": [{"name": "custom_logger",
158 "fullyQualifiedName": "custom_logger",
159 "decoratedName": "custom_logger",
160 "kind": "function"}],
161 "message": {"text": "call to ‘fprintf’ from within signal handler"}},
162 "kinds": ["danger"],
163 "nestingLevel": 2,
164 "executionOrder": 7}]}]}]}]}]}
165
166 // TODO: show the CWE
167 /* { dg-begin-multiline-output "" }
168 In function 'custom_logger':
169 ../../src/gcc/testsuite/gcc.dg/analyzer/signal-1.c:13:3: warning: call to ‘fprintf’ from within signal handler [-Wanalyzer-unsafe-call-within-signal-handler]
170 13 | fprintf(stderr, "LOG: %s", msg);
171 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172 'main': events 1-2
173 |
174 | 21 | int main(int argc, const char *argv)
175 | | ^~~~
176 | | |
177 | | (1) entry to ‘main’
178 |......
179 | 25 | signal(SIGINT, handler);
180 | | ~~~~~~~~~~~~~~~~~~~~~~~
181 | | |
182 | | (2) registering ‘handler’ as signal handler
183 |
184 event 3
185 |
186 |GNU C17:
187 | (3): later on, when the signal is delivered to the process
188 |
189 +--> 'handler': events 4-5
190 |
191 | 16 | static void handler(int signum)
192 | | ^~~~~~~
193 | | |
194 | | (4) entry to ‘handler’
195 | 17 | {
196 | 18 | custom_logger("got signal");
197 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
198 | | |
199 | | (5) calling ‘custom_logger’ from ‘handler’
200 |
201 +--> 'custom_logger': events 6-7
202 |
203 | 11 | void custom_logger(const char *msg)
204 | | ^~~~~~~~~~~~~
205 | | |
206 | | (6) entry to ‘custom_logger’
207 | 12 | {
208 | 13 | fprintf(stderr, "LOG: %s", msg);
209 | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
210 | | |
211 | | (7) call to ‘fprintf’ from within signal handler
212 |
213 { dg-end-multiline-output "" } */