- Notifications
You must be signed in to change notification settings - Fork 31.7k
/
Copy pathcoverity_model.c
179 lines (148 loc) · 3.95 KB
/
coverity_model.c
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
/* Coverity Scan model
*
* This is a modeling file for Coverity Scan. Modeling helps to avoid false
* positives.
*
* - A model file can't import any header files.
* - Therefore only some built-in primitives like int, char and void are
* available but not wchar_t, NULL etc.
* - Modeling doesn't need full structs and typedefs. Rudimentary structs
* and similar types are sufficient.
* - An uninitialized local pointer is not an error. It signifies that the
* variable could be either NULL or have some data.
*
* Coverity Scan doesn't pick up modifications automatically. The model file
* must be uploaded by an admin in the analysis settings of
* http://scan.coverity.com/projects/200
*/
/* dummy definitions, in most cases struct fields aren't required. */
#defineNULL (void *)0
#defineassert(op) /* empty */
typedefintsdigit;
typedeflongPy_ssize_t;
typedefunsigned shortwchar_t;
typedefstruct {} PyObject;
typedefstruct {} grammar;
typedefstruct {} DIR;
typedefstruct {} RFILE;
/* Python/pythonrun.c
* resource leak false positive */
voidPy_FatalError(constchar*msg) {
__coverity_panic__();
}
/* Objects/longobject.c
* NEGATIVE_RETURNS false positive */
staticPyObject*get_small_int(sdigitival)
{
/* Never returns NULL */
PyObject*p;
assert(p!=NULL);
returnp;
}
PyObject*PyLong_FromLong(longival)
{
PyObject*p;
intmaybe;
if ((ival >= -5) && (ival<257+5)) {
p=get_small_int(ival);
assert(p!=NULL);
returnp;
}
if (maybe)
returnp;
else
returnNULL;
}
PyObject*PyLong_FromLongLong(long longival)
{
returnPyLong_FromLong((long)ival);
}
PyObject*PyLong_FromSsize_t(Py_ssize_tival)
{
returnPyLong_FromLong((long)ival);
}
/* tainted sinks
*
* Coverity considers argv, environ, read() data etc as tainted.
*/
PyObject*PyErr_SetFromErrnoWithFilename(PyObject*exc, constchar*filename)
{
__coverity_tainted_data_sink__(filename);
returnNULL;
}
/* Python/fileutils.c */
wchar_t*Py_DecodeLocale(constchar*arg, size_t*size)
{
wchar_t*w;
__coverity_tainted_data_sink__(arg);
__coverity_tainted_data_sink__(size);
returnw;
}
/* Python/marshal.c */
staticPy_ssize_tr_string(char*s, Py_ssize_tn, RFILE*p)
{
__coverity_tainted_string_argument__(s);
return0;
}
staticlongr_long(RFILE*p)
{
longl;
unsigned charbuffer[4];
r_string((char*)buffer, 4, p);
__coverity_tainted_string_sanitize_content__(buffer);
l= (long)buffer;
returnl;
}
/* Coverity doesn't understand that fdopendir() may take ownership of fd. */
DIR*fdopendir(intfd)
{
DIR*d;
if (d) {
__coverity_close__(fd);
}
returnd;
}
/* Modules/_datetime.c
*
* Coverity thinks that the input values for these function come from a
* tainted source PyDateTime_DATE_GET_* macros use bit shifting.
*/
staticPyObject*
build_struct_time(inty, intm, intd, inthh, intmm, intss, intdstflag)
{
PyObject*result;
__coverity_tainted_data_sanitize__(y);
__coverity_tainted_data_sanitize__(m);
__coverity_tainted_data_sanitize__(d);
__coverity_tainted_data_sanitize__(hh);
__coverity_tainted_data_sanitize__(mm);
__coverity_tainted_data_sanitize__(ss);
__coverity_tainted_data_sanitize__(dstflag);
returnresult;
}
staticint
ymd_to_ord(intyear, intmonth, intday)
{
intord=0;
__coverity_tainted_data_sanitize__(year);
__coverity_tainted_data_sanitize__(month);
__coverity_tainted_data_sanitize__(day);
returnord;
}
staticint
normalize_date(int*year, int*month, int*day)
{
__coverity_tainted_data_sanitize__(*year);
__coverity_tainted_data_sanitize__(*month);
__coverity_tainted_data_sanitize__(*day);
return0;
}
staticint
weekday(intyear, intmonth, intday)
{
intw=0;
__coverity_tainted_data_sanitize__(year);
__coverity_tainted_data_sanitize__(month);
__coverity_tainted_data_sanitize__(day);
returnw;
}