Debian Codegraph @

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

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