-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrules.xml
211 lines (211 loc) · 6.45 KB
/
rules.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?xml version="1.0"?>
<rule>
<tokenlist>simple</tokenlist>
<pattern><![CDATA[if \( (\b\w+\b) \) { (?:g_)?free \( \b\1\b \) ; }]]></pattern>
<message>
<severity>style</severity>
<summary>Redundant condition. It is valid to free a NULL pointer.</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[\bsystem \(]]></pattern>
<message>
<severity>warning</severity>
<summary>ENV04-C. Do not call system() if you do not need a command processor</summary>
</message>
</rule>
<rule>
<tokenlist>define</tokenlist>
<pattern><![CDATA[#define \w+ (?:const\s+)?(?:char|int|short|unsigned|unsigned int |float|double)(?: [*]+)?$]]></pattern>
<message>
<severity>style</severity>
<summary>PRE03-C. Prefer typedefs to defines for encoding types</summary>
</message>
</rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[[?][?][=!('>/<-]]]></pattern>
<message>
<severity>style</severity>
<summary>PRE07-C. Avoid using repeated question marks</summary>
</message>
</rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[(?:char|int) \*+ \w+ , \w+ [^)]+;]]></pattern>
<message>
<severity>style</severity>
<summary>DCL04-C. Do not declare more than one variable per declaration</summary>
</message>
</rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[typedef [^;{}()]+ \* [^;{}()]* ;]]></pattern>
<message>
<severity>style</severity>
<summary>DCL05-C. Use typedefs of non-pointer types only</summary>
</message>
</rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[\( \) {]]></pattern>
<message>
<severity>style</severity>
<summary>DCL20-C. Always specify void even if a function accepts no arguments</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[(?:(\b\w+\b) [+-] sizeof \( \b\1\b \)|sizeof \( (\b\w+\b) \) [+-] \b\1\b)]]></pattern>
<message>
<severity>style</severity>
<summary>EXP08-C. Ensure pointer arithmetic is used correctly</summary>
</message>
</rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[sizeof \( [^)]*(?:\w+ [+-]{2}|[+-]{2} \w+)[^)]* \)]]></pattern>
<message>
<severity>warning</severity>
<summary>EXP06-C. Operands to the sizeof operator should not contain side effects</summary>
</message>
</rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[if [^{};]*(&&|\|\|)\W*(?:\b\w+\b [+-]{2}|[+-]{2} \b\w+\b)]]></pattern>
<message>
<severity>warning</severity>
<summary>EXP02-A. The second operands of the logical AND and OR operators should not contain side effects</summary>
</message>
</rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[memcmp [^{};]* sizeof \( struct \w+ \)]]></pattern>
<message>
<severity>warning</severity>
<summary>EXP04-A. Do not perform byte-by-byte comparisons between structures</summary>
</message>
</rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[(?<![>.] )(\b\w+\b)[^{};()'"]*[\[+,*/=-][^{};()'"]*(?:\b\1\b [+-]{2}|[+-]{2} \b\1\b)]]></pattern>
<message>
<severity>warning</severity>
<summary>EXP30-C. Do not depend on order of evaluation between sequence points</summary>
</message>
</rule>
<rule>
<tokenlist>normal</tokenlist>
<pattern><![CDATA[strncpy \( (\w+) , \w+ , sizeof \( \1 \) \)]]></pattern>
<message>
<severity>error</severity>
<summary>The result of strncpy(a, b, sizeof(a)) will not be null-terminated</summary>
</message>
</rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[(?<!const) (?:unsigned )?(?:char \* \w+|char \w+ \[ \]) = "]]></pattern>
<message>
<severity>style</severity>
<summary>STR05-A. Prefer making string literals const-qualified</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[mktemp \( "[^"]+" \)]]></pattern>
<message>
<severity>error</severity>
<summary>The mktemp() function modifies its string argument</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[strcpy \( \w+ , getenv \( "[^"]+" \) \)]]></pattern>
<message>
<severity>error</severity>
<summary>Buffer overrun possible for long environment variables.</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[ gets \( ]]></pattern>
<message>
<severity>error</severity>
<summary>The gets() function is obsolescent, and is deprecated</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[ rewind \( ]]></pattern>
<message>
<severity>warning</severity>
<summary>rewind() cannot report about errors, use fseek</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[ (?:ato[lif] \( |atoll \( )]]></pattern>
<message>
<severity>style</severity>
<summary>ato*() cannot report about errors, use strtol</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[(?: \+ = sn?printf| \+ sn?printf)]]></pattern>
<message>
<severity>warning</severity>
<summary>The snprintf() funciton can return -1</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[ v?sprintf \( ]]></pattern>
<message>
<severity>style</severity>
<summary>Avoid using sprintf/vsprintf</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[ f?open \( "/tmp/[^"]+" , ]]></pattern>
<message>
<severity>warning</severity>
<summary>TMP30-C. Temporary files must created with unique and unpredictable file names</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[ mktemp \(]]></pattern>
<message>
<severity>warning</severity>
<summary>The mktemp() function was marked LEGACY in the Open Group Base Specifications Issue 6</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[ signal \( [^,]+ , ([^,]+) \).* signal \( [^,]+ , \1 \)]]></pattern>
<message>
<severity>warning</severity>
<summary>SIG00-A. Avoid using the same handler for multiple signals</summary>
</message>
</rule>
<rule>
<tokenlist>raw</tokenlist>
<pattern><![CDATA[ if \( \w+ = \w+ \) { ]]></pattern>
<message>
<severity>warning</severity>
<summary>Maybe here should be == operator?</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[ if \( [^{}]+ \) { ; } { ]]></pattern>
<message>
<severity>warning</severity>
<summary>The { } block is always executed because of the ";" following the if statement</summary>
</message>
</rule>
<rule>
<pattern><![CDATA[ vfork \( ]]></pattern>
<message>
<severity>warning</severity>
<summary>Using the vfork function could result in a denial of service vulnerability</summary>
</message>
</rule>
<rule>
<tokenlist>simple</tokenlist>
<pattern><![CDATA[= (?:g_)?getenv \( "[^"]+" \) ;[^()]+?(?:g_)?(?:get|set|unset|put)env]]></pattern>
<message>
<severity>warning</severity>
<summary>The string pointed to by the return value of getenv() can be modified by a subsequent call to getenv, putenv, setenv, or unsetenv</summary>
</message>
</rule>